Part Number Hot Search : 
3S241 RURD410 SS2200 P75NE7 L8200 IRFD120 EP4861 UDA1330A
Product Description
Full Text Search
 

To Download HT56R6412 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ht56r64 tinypower tm a/d type with lcd 8-bit otp mcu rev. 1.60 1 may 21, 2012 general description the ht56r64 is a tinypower tm a/d type with lcd 8-bit high performance risc architecture microcontroller, de - signed especially for applications that interface directly to analog signals and which require an lcd interface. the device includes an integrated multi-channel analog to dig - ital converter, four pulse width modulation outputs and an lcd driver. with its fully integrated spi and i 2 c functions, designers are provided with a means of easy communication with external peripheral hardware. the benefits of integrated a/d, lcd, and pwm functions, in addition to low power consumption, high performance, i/o flexibility and low-cost, provides the device with the versatility for a wide range of products in the home appliance and in - dustrial application areas. some of these products could include electronic metering, environmental moni - toring, handheld instruments, electronically controlled tools, motor driving in addition to many others. the unique holtek tinypower technology also gives the device extremely low current consumption characteris - tics, an extremely important consideration in the present trend for low power battery powered applications. the usual holtek mcu features such as power down and wake-up functions, oscillator options, programmable frequency divider, etc. combine to ensure user applica - tions require a minimum of external components. features  operating voltage: f sys =32768hz: 2.2v~5.5v f sys =4mhz: 2.2v~5.5v f sys =8mhz: 3.0v~5.5v f sys =12mhz: 4.5v~5.5v  operating current: f sys =32khz at 3.0v: 5  a (typ.) f sys =1mhz at 3.0v: 140  a (typ.)  otp program memory: 4k 15  ram data memory: 192 8  24 bidirectional i/o lines  tinypower technology for low power operation  three pin-shared external interrupts lines and segment  single 8-bit programmable timer/event counter with overflow interrupt and 7-stage prescaler  single 16-bit programmable timer/event counter with overflow interrupt  external crystal, rc, rtc oscillator  fully integrated 32khz oscillator  externally supplied system clock option  watchdog timer function  pfd/buzzer for audio frequency generation  dual serial interfaces: spi and i 2 c  lcd driver: 33  2, 33 3or32 4  4 operating modes: normal, slow, idle and sleep  8-level subroutine nesting  8-channel 12-bit resolution a/d converter  4-channel 12-bit pwm output shared with i/o lines  low voltage reset function  2.1v, 3.15v, 4.2v  low voltage detect function  2.2v, 3.3v, 4.4v  bit manipulation instruction  15-bit table read instructions  63 powerful instructions  up to 0.33  s instruction cycle with 12mhz system clock at v dd =5v  all instructions executed in one or two machine cycles  power down and wake-up functions to reduce power consumption  52-pin qfp, 64/100-pin lqfp packages technical document  tools information  application note  ha0075e mcu reset and oscillator circuits application note
block diagram pin assignment ht56r64 rev. 1.60 2 may 21, 2012         

 
          
         
    
        
             
 
                ! "       #        
      $  % &            ' # (  )      $ ( ( 
)      *                '  (                    +   ,    -         . #     #          -        $  % &       (     ! "          
      
            
      / . 0 1 2 3 4  5 / 6 / / / . / 0 / 1 / 2 / 3 / 4 /  / 5 . 6 . / . . 0 1 0 2 0 3 0 4 0  0 5 1 1 52 62 /2 . . 0 . 1 . 2 . 3 . 4 .  . 5 0 6 0 / 0 . 0 0         
 1 61 /1 .1 01 1 1 21 31 4  ' 2  ' 3  ' 4  7 6 # ' 8 6  7 / # ' 8 /  7 . # ' 8 .  7 0 # ' 8 0  7 1 # ' 8 1  7 2 # ' 8 2 &    ( 6 #    6  ( / #    /  ( . #    .  ! - / 6 #  (   ! - 5   1   0 & ( (   .   /  !   ' 6 # 7 9  ' / # 7 9  ' .  ' 0 #  + (  ' 1  ! - . 1  ! - . 2  ! - . 3   0 #  ! - 0 .   .   /   6 & / &  ' : & $ ( /  ( 3 #    6  ( 2 #  8  /  ( 1 #  8  6  ! - / / #  (  #  ( '  ! - / . #  ;  ! - / 0 #    ! - / 1 #  $ ;  ! - / 2 #   8   ! - / 3  ! - / 4  ! - /   ! - / 5  ! - . 6  ! - . /  ! - . .  ! - . 0 1 4 1 3 1 2 1 1 1 0 1 . 1 / . / . . . 0 . 1 . 2 . 3 . 4 .  . 5 0 6 0 / 0 . 0 0 0 1 0 2 0 3 0 4 0  0 5 1 6 3 1 3 0 3 . 3 / 3 6 2 5 2  2 4 2 3 2 2 2 1 2 0 2 . 2 / 2 6 1 5 1  / . 0 1 2 3 4  5 / 6 / / / . / 0 / 1 / 2 / 3 / 4 /  / 5 . 6          
  ' 4  7 6 # ' 8 6  7 / # ' 8 /  7 . # ' 8 .  7 0 # ' 8 0  7 1 # ' 8 1  7 2 # ' 8 2 &    ( 6 #    6  ( / #    /  ( . #    .  ( 0 #    0  ( 1 #  8  6  ( 2 #  8  /  ( 3 #    6  ( 4 #    /  ! - . 1  ! - . 2  ! - . 3  ! - . 4  ! - .   ! - . 5   0 #  ! - 0 .   .   /   6 . / & $ ( . & / &  ' : & $ ( /  ! -   ! - 5  ! - / 6 #  (   ! - / / #  (  #  ( '  ! - / . #  ; #  $  ! - / 0 #    ! - / 1 #  $ ;  ! - / 2 #   8   ! - / 3  ! - / 4  ! - /   ! - / 5  ! - . 6  ! - . /  ! - . .  ! - . 0  ! - 4  ! - 3  ! - 2   1   0 & ( (   .   /  !   ' 6 # 7 9  ' / # 7 9  ' .  ' 0 #  + (  ' 1  ' 2  ' 3
pin description pin name i/o configuration option description pa0/bz pa1/bz pa2 pa3/pfd pa4~pa7 i/o bz/bz pfd bidirectional 8-bit input/output port. each individual bit on this port can be configured as a wake-up input using the pawu register. software instruc- tions determine if the pin is a cmos output or schmitt trigger input. a pull-high resistor can be connected to each pin using the papu register. pins pa0, pa1 and pa3 are shared with bz, bz and pfd respectively, the function of which is chosen via configuration option. pins pa0~pa3 can also be setup as open drain pins using the misc register. pb0/an0~ pb7/an7 i/o  bidirectional 8-bit input/output port. software instructions determine if the pin is a cmos output or schmitt trigger input. a pull-high resistor can be connected to each pin using the pbpu register. pb is pin-shared with the a/d input pins. the a/d inputs are selected via software instructions. once selected as an a/d input, the i/o function and pull-high resistor selections are disabled automatically. pd0/pwm0~ pd3/pwm3 pd4/int0 pd5/int1 pd6/tmr0 pd7/tmr1 i/o  bidirectional 8-bit input/output port. software instructions determine if the pin is a cmos output or schmitt trigger input. a pull-high resistor can be connected to each pin using the pdpu register. the pwm outputs, pwm0~pwm3, are pin shared with pins pd0~pd3, the function of which is chosen using the pwm registers. pins pd4~pd7 are pin-shared with int0, int1, tmr0 and tmr1 respectively. com0~com2 com3/seg32 o  com2~com0 are the lcd common outputs. a bit in the lcd control register determines if pin com3/seg32 is configured as a segment driver or as a common output driver. seg31~seg24 o  lcd driver outputs for lcd panel segments. ht56r64 rev. 1.60 3 may 21, 2012           
 0 / 0 . 0 0 0 1 0 2 0 3 0 4 0  0 5 1 6 1 / 1 . 1 0 1 1 1 2 1 3 1 4 1  1 5 2 6  /  .  0 1 2 3 4  55 65 /5 .5 05 15 25 35 45 5 5/ 6 6  6 4 5 4  4 4 4 3 4 2 4 1 4 0 4 . 4 / 4 6 3 5 3  3 4 3 3 3 2 3 1 3 0 3 . 3 / 3 6 2 5 2  2 4 2 3 2 2 2 1 2 0 2 . 2 / / . 0 1 2 3 4  5 / 6 / / / . / 0 / 1 / 2 / 3 / 4 /  / 5 . 6 . / . . . 0 . 1 . 2 . 3 . 4 .  . 5 0 6  ' 2  ' 3  ' 4 8 8 8 8  7 6 # ' 8 6  7 / # ' 8 /  7 . # ' 8 .  7 0 # ' 8 0  7 1 # ' 8 1  7 2 # ' 8 2  7 3 # ' 8 3  7 4 # ' 8 4 &   ' &    ( 6 #    6  ( / #    /  ( . #    .  ( 0 #    0  ( 1 #  8  6  ( 2 #  8  /  ( 3 #    6  ( 4 #    /  ! - 0  ! - 1  ! - 2  ! - 3  ! - 4  ! -   ! - 5  ! - / 6 #  (   ! - / / #  (  #  ( '  ! - / . #  ; #  $  ! - / 0 #    ! - / 1 #  $ ;  ! - / 2 #   8   ! - / 3  ! - / 4  ! - /   ! - / 5  ! - . 6  ! - . / 8 8 8 8 8 8 8  ! - . .  ! - . 0  ! - . 1  ! - . 2  ! - . 3  ! - . 4  ! - .   ! - . 5  ! - 0 6  ! - 0 /   0 #  ! - 0 .   .   /   6 . / & $ ( . & / &  ' : & $ ( / 8 8 8 8  ! - .  ! - /  ! - 6 8 8 8 8 8 8 8 8 8   1   0 & ( ( &  ! + ' & ( (   .   /  !   ' 6 # 7 9  ' / # 7 9  ' .  ' 0 #  + (  ' 1
pin name i/o configuration option description seg23~seg16 o  a bit in the lcd control register determines if the pins are to be used as segment drivers or as cmos outputs. seg8~seg9 seg10/sdo seg11/sdi/sda seg12/sck/scl seg13/scs seg14/pclk seg15/pint o o i/o i/o i/o o i/o i 2 c spi pclk pint seg8 and seg9 are lcd driver outputs. seg10 is pin-shared with the serial interface output line, sdo. seg11 is pin-shared with the spi bus data line, sdi and the i 2 c bus data line sda. seg12, is pin-shared with the spi bus clock line, sck, and the i 2 c bus clock line scl. seg13 is pin-shared with the serial interface select line, scs . seg14 is pin-shared with the peripheral clock line, pclk. seg15 is pin-shared with the peripheral interrupt line, pint . all of the seg8~seg15 lines can be chosen to be either segment drivers or as logical outputs using lcd control bits. seg0~seg7 o  lcd driver outputs for lcd panel segments. seg0~seg7 can be chosen to be either segment drivers or as logical outputs using lcd control bits. osc1 osc2 i o crystal or rc or ec osc1, osc2 are connected to an external rc network or external crys - tal, determined by configuration option, for the internal system clock. if the rc system clock option is selected, pin osc2 can be used to measure the system clock at 1/4 frequency. ec is external clock mode, we can input clock source directly to osc1 pin. osc3 osc4 i o rtc osc3 and osc4 are connected to a 32768hz crystal oscillator to form a real time clock for f sub or f sl . res i  schmitt trigger reset input. active low. vlcd1  lcd power supply vref i  reference voltage input pin. vmax i  ic maximum voltage, connect to v dd ,v lcd or v1 v1, vlcd2, c1, c2 i  lcd voltage pump vdd  positive power supply avdd  analog positive power supply. vss  negative power supply, ground avss  analog negative power supply, ground note: the pin description table represents the largest package available, therefore some of the pins and functions may not be available on smaller package types. absolute maximum ratings supply voltage ...........................v ss  0.3v to v ss +6.0v storage temperature ............................ 50 cto125 c input voltage..............................v ss  0.3v to v dd +0.3v operating temperature........................... 40 cto85 c i ol total ..............................................................150ma i oh total............................................................ 100ma total power dissipation .....................................500mw note: these are stress ratings only. stresses exceeding the range specified under  absolute maximum ratings  may cause substantial damage to the device. functional operation of this device at other conditions beyond those listed in the specification is not implied and prolonged exposure to extreme conditions may affect device reliability. ht56r64 rev. 1.60 4 may 21, 2012
d.c. characteristics ta=25 c symbol parameter test conditions min. typ. max. unit v dd conditions v dd operating voltage  f sys =4mhz 2.2  5.5 v f sys =8mhz 3.0  5.5 v f sys =12mhz 4.5  5.5 v av dd analog operating voltage  v ref =av dd 3.0  5.0 v i dd1 operating current (crystal osc, rc osc) 3v no load, f sys =f m =1mhz adc off  140 210 a 5v  320 480 a i dd2 operating current (crystal osc, rc osc) 3v no load, f sys =f m =2mhz adc off  200 300 a 5v  440 660 a i dd3 operating current (crystal osc, rc osc) 3v no load, f sys =f m =4mhz adc off  400 600 a 5v  800 1200 a i dd4 operating current (ec mode, filter on) 3v no load, f sys =f m =4mhz adc off  320 480 a 5v  550 820 a i dd5 operating current (ec mode, filter off) 3v no load, f sys =f m =4mhz adc off  300 450 a 5v  530 800 a i dd6 operating current (crystal osc, rc osc) 5v no load, f sys =f m =8mhz adc off  1.5 3.0 ma i dd7 operating current (crystal osc, rc osc) 5v no load, f sys =f m =12mhz adc off  2.0 4.0 ma i dd8 operating current (slow mode, f m =4mhz) (crystal osc, rc osc) 3v no load, f sys =f slow =500khz adc off  130 200 a 5v  300 450 a i dd9 operating current (slow mode, f m =4mhz) (crystal osc, rc osc) 3v no load, f sys =f slow =1mhz adc off  170 260 a 5v  370 560 a i dd10 operating current (slow mode, f m =4mhz) (crystal osc, rc osc) 3v no load, f sys =f slow =2mhz adc off  250 380 a 5v  520 780 a i dd11 operating current (slow mode, f m =8mhz) (crystal osc, rc osc) 3v no load, f sys =f slow =1mhz adc off  220 330 a 5v  480 720 a i dd12 operating current (slow mode, f m =8mhz) (crystal osc, rc osc) 3v no load, f sys =f slow =2mhz adc off  300 450 a 5v  630 950 a i dd13 operating current (slow mode, f m =8mhz) (crystal osc, rc osc) 3v no load, f sys =f slow =4mhz adc off  460 690 a 5v  920 1380 a i dd14 operating current (f sys =32768hz (note 1) or 32k_int internal rc osc) 3v no load, wdt off, adc off, lcd on (note 2), r type, v lcd =v dd , 1 / 2 bias (r bias =400k )  12 18 a 5v  18 24 a i dd15 operating current (f sys =32768hz (note 1) or 32k_int internal rc osc) 3v no load, wdt off, adc off, lcd on (note 2), r type, v lcd =v dd , 1 / 3 bias (r bias =600k )  10 15 a 5v  15 22 a ht56r64 rev. 1.60 5 may 21, 2012
symbol parameter test conditions min. typ. max. unit v dd conditions i dd16 operating current (f sys =32768hz (note 1) or 32k_int internal rc osc) 3v no load, wdt off, adc off, lcd on (note 2), c type 1 / 3 bias, v lcd =3v  69 a 5v  913 a i dd17 operating current (f sys =32768hz (note 1) or 32k_int internal rc osc) 3v no load, lcd off, wdt off, adc off  58 a 5v  812 a i stb1 standby current ( sleep) (f sys ,f sub ,f s ,f lcd ,f wdt =off) 3v no load, system halt, wd off  0.1 1.0 a 5v  0.2 2.0 a i stb2 standby current ( sleep) (f sys ,f lcd =off; f lcd ,f wdt =f sub =32768hz (note 1) or 32k_int rc osc) 3v no load, system halt, wdt on  12 a 5v  35 a i stb3 standby current ( idle) (f sys ,f wdt =off; f s (note 3)= f sub =32768hz (note 1) or 32k_int rc osc) 3v no load, system halt, wdt off, lcd on (note 2), 1 / 2 bias, c type, v lcd =v dd  12 a 5v  35 a i stb4 standby current ( idle) (f sys ,f wdt =off; f s (note 3)= f sub =32768hz (note 1) or 32k_int rc osc) 3v no load, system halt, wdt off, lcd on (note 2), 1 / 3 bias, c type, v lcd =3v  12 a 5v  35 a i stb5 standby current ( idle) (f sys ,f wdt =off; f s (note 3)= f sub =32768hz (note 1) or 32k_int rc osc) 3v no load, system halt, wdt off, lcd on (note 2), r type, v lcd =v dd , 1 / 2 bias (r bias =400k )  10 15 a 5v  15 22 a i stb6 standby current ( idle) (f sys ,f wdt =off; f s (note 3)= f sub =32768hz (note 1) or 32k_int rc osc) 3v no load, system halt, wdt off, lcd on (note 2), r type, v lcd =v dd , 1 / 3 bias (r bias =600k )  69 a 5v  10 15 a i stb7 standby current ( idle) (f sys =on, f sys =f m =4mhz, f wdt ,f lcd =off, f s (note 3)=f sub =32768hz (note 1) or 32k_int rc osc) 3v no load, system halt, wdt off, lcd off, spi or i 2 c on, pclk on, pclk=f sys /8  150 220 a 5v  350 530 a v il1 input low voltage for i/o ports, tmr and int  0  0.3v dd v v ih1 input high voltage for i/o ports, tmr and int  0.7v dd  v dd v v il2 input low voltage (res )  0  0.4v dd v v ih2 input high voltage (res )  0.9v dd  v dd v v lvr low voltage reset voltage  configuration option: 2.1v 1.98 2.10 2.22 v  configuration option: 3.15v 2.98 3.15 3.32 v  configuration option: 4.2v 3.98 4.20 4.42 v v lvd low voltage detector voltage  configuration option: 2.2v 2.08 2.20 2.32 v  configuration option: 3.3v 3.12 3.30 3.50 v  configuration option: 4.4v 4.12 4.40 4.70 v i ol1 i/o port sink current 3v v ol =0.1v dd 612  ma 5v 10 25  ma ht56r64 rev. 1.60 6 may 21, 2012
symbol parameter test conditions min. typ. max. unit v dd conditions i oh1 i/o port source current 3v v oh =0.9v dd 2 4  ma 5v 5 8  ma i ol2 lcd common and segment current 3v v ol =0.1v dd 210 420  a 5v 350 700  a i oh2 lcd common and segment current 3v v oh =0.9v dd 80 160  a 5v 180 360  a r ph pull-high resistance for i/o ports 3v  20 60 100 k 5v 10 30 50 k note: 1. 32768hz is in slow start mode (rtcc.4=1) for the d.c. current measurement. 2. lcd waveform is in type a condition. 3. f s is the internal clock for buzzer, rtc, time base and wdt. 4. both timer/event counters are off. timer filter is disabled for all test conditions. a.c. characteristics ta=25 c symbol parameter test conditions min. typ. max. unit v dd conditions f sys1 system clock (crystal osc, rc osc)  2.2v~5.5v 32  4000 khz 3.0v~5.5v 32  8000 khz 4.5v~5.5v 32  12000 khz f sys2 system clock (rtc crystal osc)  2.2v~5.5v  32768  hz f rtcosc rtc frequency   32768  hz f timer timer i/p frequency (tmr0/tmr1)  2.2v~5.5v 0  4000 khz 3.3v~5.5v 0  8000 khz 4.5v~5.5v 0  12000 khz f rc32k 32k rc oscillator  2.2v~5.5v, after trim 28.8 32.0 35.2 khz t res external reset low pulse width  1   s t lvr low voltage reset time  0.1 0.4 0.6 ms t lvdo time for lvdo become stable, lvdc is enabled   100 s t sst1 system start-up timer period  power-on  1024  t sys * t sst2 system start-up timer period for xtal or rtc oscillator  wake-up from power down mode  1024  t sys * t sst3 system start-up timer period for external rc or external clock  wake-up from power down mode  12 t sys * t int interrupt pulse width  1   s note: *t sys =1/f sys1 or 1/f sys2 ht56r64 rev. 1.60 7 may 21, 2012
adc characteristics ta=25 c symbol parameter test conditions min. typ. max. unit v dd conditions v ad a/d input voltage  52qfp, 64lqfp 0  av dd v 100lqfp 0  v ref v v ref a/d input reference voltage range  av dd =5v 1.6  av dd +0.1 v dnl a/c differential non-linearity  av dd =5v, v ref =av dd , t ad =0.5s 2  2 lsb inl adc integral non-linearity  av dd =5v, v ref =av dd , t ad =0.5s 4  4 lsb i adc additional power consumption if a/d converter is used 3v   0.50 0.75 ma 5v  1.00 1.50 ma t ad a/d clock period  0.5  s t adc a/d conversion time   16  t ad power-on reset characteristics ta=25 c symbol parameter test conditions min. typ. max. unit v dd conditions v por vdd start voltage to ensure power-on reset   0mv rr vdd vdd raising rate to ensure power-on reset  0.05  v/ms t por minimum time for vdd stays at v por to ensure power-on reset  200  ms ht56r64 rev. 1.60 8 may 21, 2012
ht56r64 rev. 1.60 9 may 21, 2012 system architecture a key factor in the high-performance features of the holtek range of microcontrollers is attributed to their in - ternal system architecture. the range of devices take advantage of the usual features found within risc microcontrollers providing increased speed of operation and enhanced performance. the pipelining scheme is implemented in such a way that instruction fetching and instruction execution are overlapped, hence instructions are effectively executed in one cycle, with the exception of branch or call instructions. an 8-bit wide alu is used in practically all instruction set operations, which carries out arithmetic operations, logic operations, rotation, in - crement, decrement, branch decisions, etc. the internal data path is simplified by moving data through the accu - mulator and the alu. certain internal registers are im - plemented in the data memory and can be directly or indirectly addressed. the simple addressing methods of these registers along with additional architectural fea - tures ensure that a minimum of external components is required to provide a functional i/o and a/d control sys - tem with maximum reliability and flexibility. this makes the device suitable for low-cost, high-volume production for controller applications. clocking and pipelining the main system clock, derived from either a crys- tal/resonator or rc oscillator is subdivided into four in- ternally generated non-overlapping clocks, t1~t4. the program counter is incremented at the beginning of the t1 clock during which time a new instruction is fetched. the remaining t2~t4 clocks carry out the decoding and execution functions. in this way, one t1~t4 clock cycle forms one instruction cycle. although the fetching and execution of instructions takes place in consecutive in - struction cycles, the pipelining structure of the microcontroller ensures that instructions are effectively executed in one instruction cycle. the exception to this are instructions where the contents of the program counter are changed, such as subroutine calls or jumps, in which case the instruction will take one more instruction cycle to execute. when the rc oscillator is used, osc2 is free for use as a t1 phase clock synchronizing pin. this t1 phase clock has a frequency of f sys /4 with a 1:3 high/low duty cycle. for instructions involving branches, such as jump or call instructions, two machine cycles are required to com - plete instruction execution. an extra cycle is required as the program takes one cycle to first obtain the actual jump or call address and then another cycle to actually execute the branch. the requirement for this extra cycle should be taken into account by programmers in timing sensitive applications. +        <  =  > ! "         <  =   / > +        <  =  ? / > ! "         <  =  > +        <  =  ? . > ! "         <  =  ? / >   ? /  ? .  
         * =         * >         *   /                     *   .         *   0         *   1 
 

 system clocking and pipelining +        <  / ! "         <  / +        <  . +      
 
 / . 0 1 2 3  ( ! $ ' @ a   &  ' b c / . d e ' $ $  ( ! $ ' @  $  c / . d e a a 8   ! "         <  . +        <  0 +        <  3 ! "         <  3 +        <  4 instruction fetching
ht56r64 rev. 1.60 10 may 21, 2012 program counter during program execution, the program counter is used to keep track of the address of the next instruction to be executed. it is automatically incremented by one each time an instruction is executed except for instructions, such as jmp or call that demand a jump to a non-consecutive program memory address. it must be noted that only the lower 8 bits, known as the program counter low register, are directly addressable. when executing instructions requiring jumps to non-consecutive addresses such as a jump instruction, a subroutine call, interrupt or reset, etc., the microcontroller manages program control by loading the required address into the program counter. for condi - tional skip instructions, once the condition has been met, the next instruction, which has already been fetched during the present instruction execution, is dis - carded and a dummy cycle takes its place while the cor - rect instruction is obtained. the lower byte of the program counter, known as the program counter low register or pcl, is available for program control and is a readable and writable register. by transferring data directly into this register, a short pro - gram jump can be executed directly, however, as only this low byte is available for manipulation, the jumps are limited to the present page of memory, that is 256 loca - tions. when such program jumps are executed it should also be noted that a dummy cycle will be inserted. the lower byte of the program counter is fully accessi - ble under program control. manipulating the pcl might cause program branching, so an extra cycle is needed to pre-fetch. further information on the pcl register can be found in the special function register section. mode program counter bits b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0 initial reset 0 0 0000000000 external interrupt 0 0 0 0000000100 external interrupt 1 0 0 0000001000 timer/event counter 0 overflow 0 0 0000001100 timer/event counter 1 overflow 0 0 0000010000 spi/i 2 c interrupt 0 0 0000010100 multi-function interrupt 0 0 0000011000 skip program counter + 2 loading pcl pc11 pc10 pc9 pc8 @7 @6 @5 @4 @3 @2 @1 @0 jump, call branch #11 #10 #9 #8 #7 #6 #5 #4 #3 #2 #1 #0 return from subroutine s11 s10 s9 s8 s7 s6 s5 s4 s3 s2 s1 s0 program counter note: pc11~pc8: current program counter bits @7~@0: pcl bits #11~#0: instruction code address bits s11~s0: stack register bits
ht56r64 rev. 1.60 11 may 21, 2012 stack this is a special part of the memory which is used to save the contents of the program counter only. the stack has 12 levels and is neither part of the data nor part of the program space, and is neither readable nor writeable. the activated level is indexed by the stack pointer, sp, and is neither readable nor writeable. at a subroutine call or interrupt acknowledge signal, the con - tents of the program counter are pushed onto the stack. at the end of a subroutine or an interrupt routine, sig - naled by a return instruction, ret or reti, the program counter is restored to its previous value from the stack. after a device reset, the stack pointer will point to the top of the stack. if the stack is full and an enabled interrupt takes place, the interrupt request flag will be recorded but the ac- knowledge signal will be inhibited. when the stack pointer is decremented, by ret or reti, the interrupt will be serviced. this feature prevents stack overflow al- lowing the programmer to use the structure more easily. however, when the stack is full, a call subroutine in- struction can still be executed which will result in a stack overflow. precautions should be taken to avoid such cases which might cause unpredictable program branching. arithmetic and logic unit  alu the arithmetic-logic unit or alu is a critical area of the microcontroller that carries out arithmetic and logic op - erations of the instruction set. connected to the main microcontroller data bus, the alu receives related in - struction codes and performs the required arithmetic or logical operations after which the result will be placed in the specified register. as these alu calculation or oper - ations may result in carry, borrow or other status changes, the status register will be correspondingly up - dated to reflect these changes. the alu supports the following functions:  arithmetic operations: add, addm, adc, adcm, sub, subm, sbc, sbcm, daa  logic operations: and, or, xor, andm, orm, xorm, cpl, cpla  rotation rra, rr, rrca, rrc, rla, rl, rlca, rlc  increment and decrement inca, inc, deca, dec  branch decision, jmp, sz, sza, snz, siz, sdz, siza, sdza, call, ret, reti program memory the program memory is the location where the user code or program is stored. for this device the program memory is an otp type, which means it can be pro - grammed only one time. by using the appropriate pro - gramming tools, this otp memory device offer users the flexibility to conveniently debug and develop their applications while also offering a means of field pro - gramming. the program memory is used to store the program in - structions, which are to be executed. it also contains data, table, and interrupt entries, and is organized into 4096 15 bits format which are addressed by the pro - gram counter and table pointer. the jmp and call in - structions provide only 11 bits of address to allow branching within any 4k program memory. when doing a jmp or call instruction. structure the program memory has a capacity of 4k by 15 bits. the program memory is addressed by the program counter and also contains data, table information and interrupt entries. table data, which can be setup in any location within the program memory, is addressed by a separate table pointer register. special vectors within the program memory, certain locations are re- served for special usage such as reset and interrupts.  location 000h this vector is reserved for use by the device reset for program initialisation. after a device reset is initiated, the program will jump to this location and begin execution.  location 004h this vector is used by the external interrupt 0. if the external interrupt pin receives an active edge, the pro - gram will jump to this location and begin execution if the external interrupt is enabled and the stack is not full.  location 008h this vector is used by the external interrupt 1. if the external interrupt pin receives an active edge, the pro - gram will jump to this location and begin execution if the external interrupt is enabled and the stack is not full.  location 00ch this internal vector is used by the timer/event coun - ter 0. if a timer/event counter 0 overflow occurs, the program will jump to this location and begin execution if the timer/event counter interrupt is enabled and the stack is not full.                *  $  )    /    *  $  )    .    *  $  )    0    *  $  )    / .                f     *    *  
   7       f     *
ht56r64 rev. 1.60 12 may 21, 2012  location 010h this internal vector is used by the timer/event coun - ter 1. if a timer/event counter 1 overflow occurs, the program will jump to this location and begin execution if the timer/event counter interrupt is enabled and the stack is not full.  location 014h this internal vector is used by the spi/i 2 c interrupt. when either an spi or i 2 c bus, dependent upon which one is selected, requires data transfer, the program will jump to this location and begin execution if the spi/i 2 c interrupt is enabled and the stack is not full.  location 018h this internal vector is used by the multi-function inter - rupt. when the time base overflows, the real time clock overflows, the a/d converter completes its con - version process, or an active edge appears on the ex - ternal peripheral interrupt pin, the program will jump to this location and begin execution if the relevant inter - rupt is enabled and the stack is not full. look-up table any location within the program memory can be defined as a look-up table where programmers can store fixed data. to use the look-up table, the table pointer must first be setup by placing the lower order address of the look up data to be retrieved in the table pointer register, tblp. this register defines the lower 8-bit address of the look-up table. after setting up the table pointer, the table data can be retrieved from the current program memory page or last program memory page using the  tabrdc[m]  or  tabrdl [m] instructions, respectively. when these in - structions are executed, the lower order table byte from the program memory will be transferred to the user de - fined data memory register [m] as specified in the in - struction. the higher order table data byte from the program memory will be transferred to the tblh special register. any unused bits in this transferred higher order byte will be read as 0. the following diagram illustrates the addressing/data flow of the look-up table: 8           / 2  
  6 / 1 d 

 
  
 &     ! "        8  6         &     
         6         &        #  .         &     6 6 6 d 6 6 1 d 6 6  d 6 6 d 6 / 6 d 6 /  d + + + d ! "        8  /         &     
         /         &        
g +  
         &     program memory structure instruction table location bits b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0 tabrdc [m] pc11 pc10 pc9 pc8 @7 @6 @5 @4 @3 @2 @1 @0 tabrdl [m]1111@7@6@5@4@3@2@1@0 table location note: pc11~pc8: current program counter bits @7~@0: table pointer tblp bits                                 d
   7     7 $   7 $ d  
f
      c e             d
   7                $  %  7   
ht56r64 rev. 1.60 13 may 21, 2012 table program example the following example shows how the table pointer and table data is defined and retrieved from the microcontroller. this example uses raw table data lo - cated in the last page which is stored there using the org statement. the value at this org statement is 700h which refers to the start address of the last page within the 2k program memory of the device. the table pointer is setup here to have an initial value of 06h. this will ensure that the first data read from the data ta - ble will be at the program memory address 706h or 6 locations after the start of the last page. note that the value for the table pointer is referenced to the first ad - dress of the present page if the  tabrdc [m] instruc - tion is being used. the high byte of the table data which in this case is equal to zero will be transferred to the tblh register automatically when the  tabrdl [m] in - struction is executed. because the tblh register is a read-only register and cannot be restored, care should be taken to ensure its protection if both the main routine and interrupt service routine use table read instructions. if using the table read instructions, the interrupt service routines may change the value of the tblh and subsequently cause errors if used again by the main routine. as a rule it is recommended that simultaneous use of the table read instructions should be avoided. however, in situations where simultaneous use cannot be avoided, the inter - rupts should be disabled prior to the execution of any main routine table-read instructions. note that all table related instructions require two instruction cycles to complete their operation. tempreg1 db ? ; temporary register #1 tempreg2 db ? ; temporary register #2 : : mov a,06h ; initialise table pointer - note that this address ; is referenced mov tblp,a ; to the last page or present page : : tabrdl tempreg1 ; transfers value in table referenced by table pointer ; to tempregl ; data at prog. memory address 706h transferred to ; tempreg1 and tblh dec tblp ; reduce value of table pointer by one tabrdl tempreg2 ; transfers value in table referenced by table pointer ; to tempreg2 ; data at prog.memory address 705h transferred to ; tempreg2 and tblh ; in this example the data 1ah is transferred to ; tempreg1 and data 0fh to register tempreg2 : : org 700h ; sets initial address of last page dc 00ah, 00bh, 00ch, 00dh, 00eh, 00fh, 01ah, 01bh : :
ht56r64 rev. 1.60 14 may 21, 2012 data memory the data memory is a volatile area of 8-bit wide ram internal memory and is the location where temporary in - formation is stored. divided into three sections, the first of these is an area of ram where special function regis - ters are located. these registers have fixed locations and are necessary for correct operation of the device. many of these registers can be read from and written to directly under program control, however, some remain protected from user manipulation. the second area of data memory is reserved for general purpose use. all locations within this area are read and write accessible under program control. the third area is reserved for the lcd memory. this special area of data memory is mapped directly to the lcd display so data written into this memory area will directly affect the displayed data. the addresses of the lcd memory area overlap those in the general purpose data memory area, switching between the two areas is achieved by setting the bank pointer to the correct value. structure the data memory is subdivided into 2 banks, known as bank 0 and bank 1, all of which are implemented in 8-bit wide ram. ram data memory located in bank 0 is sub - divided into two sections, the special purpose data memory and the general purpose data memory. the start address of the ram data memory for all devices is the address 00h . the last data memory address is ffh. bank 1 is for lcd display memory which occupy 128 8 location. general purpose data memory all microcontroller programs require an area of read/write memory where temporary data can be stored and retrieved for use later. it is this area of ram memory that is known as general purpose data memory. this area of data memory is fully accessible by the user pro - gram for both read and write operations. by using the  set [m].i and  clr [m].i instructions individual bits can be set or reset under program control giving the user a large range of flexibility for bit manipulation in the data memory. special purpose data memory this area of data memory is where registers, necessary for the correct operation of the microcontroller, are stored. most of the registers are both read and write type but some are protected and are read only, the details of which are located under the relevant special function register section. note that for locations that are unused, any read instruction to these addresses will return the value 00h. -             (           
         (          6 6 d 1 6 d + + d 0 + d 7  *  6 7  *  / 7  *  / $ (      1 6 d 3 6 d bank 0 ram data memory structure note: most of the data memory bits can be directly manipulated using the  set [m].i and clr [m].i with the exception of a few dedicated bits. the data memory can also be accessed through the memory pointer registers mp0 and mp1.  '  6   6  '  /   / 7  '  $  7 $   7 $ d     '     8  6    6    6    / d    / $    /  '  '  7  7  (  (    6 $    6 d    / $    / d  8  / 6 6 d 6 / d 6 . d 6 0 d 6 1 d 6 2 d 6 3 d 6 4 d 6  d 6 5 d 6 ' d 6 7 d 6 d 6 ( d 6 ! d 6 + d / 6 d / / d / . d / 0 d / 1 d / 2 d / 3 d / 4 d /  d / 5 d / ' d / 7 d / d / ( d / ! d / + d    . $    . d    0 $    0 d ' (  $ ' (  d ' (  '   $ ;   (  '    '    7    (    8  ! ( - ! $ (   $ $ (    / $ (    .     +      8 6     8 /    (     '  #     8 . . 6 d . / d . . d . 0 d . 1 d . 2 d . 3 d . 4 d .  d . 5 d . ' d . 7 d . d . ( d . ! d . + d 0 6 d 0 / d 0 . d 0 0 d 0 1 d 0 2 d 0 3 d 0 4 d 0  d 0 5 d 0 ' d 0 7 d 0 d 0 ( d 0 ! d 0 + d a                h 6 6 h  special purpose ram data memory
ht56r64 rev. 1.60 15 may 21, 2012 lcd memory the data to be displayed on the lcd is also stored in an area of fully accessible data memory. by writing to this area of ram, the lcd display output can be directly controlled by the application program. as the lcd mem - ory exists in bank 1, but have addresses which map into the general purpose data memory, it is necessary to first ensure that the bank pointer is set to the value 01h before accessing the lcd memory. the lcd memory can only be accessed indirectly using the memory pointer mp1 and the indirect addressing register iar1. when the bank pointer is set to bank 1 to access the lcd data memory, if any addresses with a value less than 40h are read, the special purpose memory in bank 0 will be accessed. also, if the bank pointer is set to bank 1, if any addresses higher than the last address in bank 1 are read, then a value of 00h will be returned. special function registers to ensure successful operation of the microcontroller, certain internal registers are implemented in the data memory area. these registers ensure correct operation of internal functions such as timers, interrupts, etc., as well as external functions such as i/o data control and a/d converter operation. the location of these registers within the data memory begins at the address 00h. any unused data memory locations between these special function registers and the point where the general pur- pose memory begins is reserved for future expansion purposes, attempting to read data from these locations will return a value of 00h. indirect addressing registers  iar0, iar1 the indirect addressing registers, iar0 and iar1, al - though having their locations in normal ram register space, do not actually physically exist as normal regis - ters. the method of indirect addressing for ram data manipulation uses these indirect addressing registers and memory pointers, in contrast to direct memory ad - dressing, where the actual memory address is speci - fied. actions on the iar0 and iar1 registers will result in no actual read or write operation to these registers but rather to the memory location specified by their corre - sponding memory pointer, mp0 or mp1. acting as a pair, iar0 and mp0 can together access data bank 0 while the iar1 and mp1 register pair can access data from bank 0 and bank 1. as the indirect addressing registers are not physically implemented, reading the indirect addressing registers indirectly will return a re - sult of 00h and writing to the registers indirectly will re - sult in no operation. memory pointers  mp0, mp1 for all devices, two memory pointers, known as mp0 and mp1 are provided. these memory pointers are physically implemented in the data memory and can be manipulated in the same way as normal registers pro- viding a convenient way with which to address and track data. when any operation to the relevant indirect ad- dressing registers is carried out, the actual address that the microcontroller is directed to, is the address speci- fied by the related memory pointer. mp0, together with indirect addressing register, iar0, are used to access data from bank 0, while mp1 and iar1 are used to ac- cess data from bank 0 and bank 1. the following example shows how to clear a section of four ram locations already defined as locations adres1 to adres4. data .section
data
adres1 db ? adres2 db ? adres3 db ? adres4 db ? block db ? code .section at 0
code
org 00h start: mov a,04h ; setup size of block mov block,a mov a,offset adres1 ; accumulator loaded with first ram address mov mp0,a ; setup memory pointer with first ram address loop: clr iar0 ; clear the data at address defined by mp0 inc mp0 ; increment memory pointer sdz block ; check if last memory location has been cleared jmp loop continue: the important point to note here is that in the example shown above, no reference is made to specific ram addresses.
ht56r64 rev. 1.60 16 may 21, 2012 bank pointer  bp the data memory is divided into 2 banks, known as bank 0 and bank 1. selecting the required data memory area is achieved using the bank pointer. if data in bank 0 is to be accessed, then the bp register must be loaded with the value 00h, while if data in bank 1 is to be ac - cessed, then the bp register must be loaded with the value 01h. the data memory is initialised to bank 0 after a reset, except for the wdt time-out reset in the power down mode, in which case, the data memory bank remains unaffected. it should be noted that the special function data memory is not affected by the bank selection, which means that the special function registers can be accessed from within either bank 0 or bank 1. directly addressing the data memory will always result in bank 0 being accessed irrespective of the value of the bank pointer. accumulator  acc the accumulator is central to the operation of any microcontroller and is closely related with operations carried out by the alu. the accumulator is the place where all intermediate results from the alu are stored. without the accumulator it would be necessary to write the result of each calculation or logical operation such as addition, subtraction, shift, etc., to the data memory resulting in higher programming and timing overheads. data transfer operations usually involve the temporary storage function of the accumulator; for example, when transferring data between one user defined register and another, it is necessary to do this by passing the data through the accumulator as no direct transfer between two registers is permitted. program counter low register  pcl to provide additional program control functions, the low byte of the program counter is made accessible to pro - grammers by locating it within the special purpose area of the data memory. by manipulating this register, direct jumps to other program locations are easily imple - mented. loading a value directly into this pcl register will cause a jump to the specified program memory lo - cation, however, as the register is only 8-bit wide, only jumps within the current program memory page are per - mitted. when such operations are used, note that a dummy cycle will be inserted. look-up table registers  tblp, tblh these two special function registers are used to control operation of the look-up table which is stored in the pro - gram memory. tblp is the table pointer and indicates the location where the table data is located. its value must be setup before any table read commands are ex - ecuted. its value can be changed, for example using the inc or dec instructions, allowing for easy table data pointing and reading. tblh is the location where the high order byte of the table data is stored after a table read data instruction has been executed. note that the lower order table data byte is transferred to a user de - fined location. status register  status this 8-bit register contains the zero flag (z), carry flag (c), auxiliary carry flag (ac), overflow flag (ov), power down flag (pdf), and watchdog time-out flag (to). these arithmetic/logical operation and system manage- ment flags are used to record the status and operation of the microcontroller. with the exception of the to and pdf flags, bits in the status register can be altered by instructions like most           4  6 7  6 7  6     (             6       7  *  6    /       7  *  / 8   
      b  % 
   h 6 h     bank pointer    ( +  & 9 '                               !   "    # $ "        f    '  "

         f    9     f     )   f   %  f     %     & " # "     #  $ "     %      %  f            
      f    8   
      b          h 6 h  4  6 status register
ht56r64 rev. 1.60 17 may 21, 2012 other registers. any data written into the status register will not change the to or pdf flag. in addition, opera - tions related to the status register may give different re - sults due to the different instruction operations. the to flag can be affected only by a system power-up, a wdt time-out or by executing the  clr wdt or halt in - struction. the pdf flag is affected only by executing the halt or  clr wdt instruction or during a system power-up. the z, ov, ac and c flags generally reflect the status of the latest operations.  c is set if an operation results in a carry during an ad - dition operation or if a borrow does not take place dur - ing a subtraction operation; otherwise c is cleared. c is also affected by a rotate through carry instruction.  ac is set if an operation results in a carry out of the low nibbles in addition, or no borrow from the high nib - ble into the low nibble in subtraction; otherwise ac is cleared.  z is set if the result of an arithmetic or logical operation is zero; otherwise z is cleared.  ov is set if an operation results in a carry into the high - est-order bit but not a carry out of the highest-order bit, or vice versa; otherwise ov is cleared.  pdf is cleared by a system power-up or executing the  clr wdt instruction. pdf is set by executing the halt instruction.  to is cleared by a system power-up or executing the  clr wdt or halt instruction. to is set by a wdt time-out. in addition, on entering an interrupt sequence or execut- ing a subroutine call, the status register will not be pushed onto the stack automatically. if the contents of the status registers are important and if the subroutine can corrupt the status register, precautions must be taken to correctly save it. interrupt control register  intc0, intc1, mfic, intedge these 8-bit registers, control the operation of the device interrupt functions. by setting various bits within these registers using standard bit manipulation instructions, the enable/disable function of each interrupt can be inde - pendently controlled. a master interrupt bit within this reg - ister, the emi bit, acts like a global enable/disable and is used to set all of the interrupt enable bits on or off. this bit is cleared when an interrupt routine is entered to disable further interrupt and is set by executing the  reti in - struction. the intedge register is used to select the ac - tive edges for the two external interrupt pins int0 and int1. timer/event counter registers  tmr0, tmr1l/ tmr1h, tmr0c, tmr1c the device contains one internal 8-bit timer/event counter and one 16-bit timer/event counter. the registers tmr0 and tmr1l/tmr1h are the locations where the timer values are located. these register can also be preloaded with fixed data to allow different time intervals to be setup. two associated control registers, tmr0c and tmr1c, contains the setup information for these timers, which determines in what mode the timer is to be used as well as containing the timer on/off control function. input/output ports and control registers within the area of special function registers, the i/o registers and their associated control registers play a prominent role. all i/o ports have a designated register correspondingly labeled as pa, pb and pd. these la - beled i/o registers are mapped to specific addresses within the data memory as shown in the data memory table, which are used to transfer the appropriate output or input data on that port. with each i/o port there is an associated control register labeled pac, pbc and pdc, also mapped to specific addresses with the data mem - ory. the control register specifies which pins of that port are set as inputs and which are set as outputs. to setup a pin as an input, the corresponding bit of the control register must be set high, for an output it must be set low. during program initialization, it is important to first setup the control registers to specify which pins are out- puts and which are inputs before reading data from or writing data to the i/o ports. one flexible feature of these registers is the ability to directly program single bits us- ing the  set [m].i and  clr [m].i instructions. the ability to change i/o pins from output to input and vice versa by manipulating specific bits of the i/o control reg- isters during normal program operation is a useful fea- ture of these devices. pulse width modulator registers the device contains four pulse width modulator function with their own related independent control register, known as pwm0l, pwm0h, pwm1l, pwm1h, pwm2l, pwm2h, pwm3l and pwm3h. the 12-bit contents of each register pair, defines the duty cycle value for the modulation cycle of the pulse width modulator. a/d converter registers  adrl, adrh, adcr, acsr the device contains an 8-channel 12-bit a/d converter. the correct operation of the a/d requires the use of two data registers and two control registers. the two data registers, a high byte data register known as adrh, and a low byte data register known as adrl, are the register locations where the digital value is placed after the com - pletion of an analog to digital conversion cycle. func - tions such as the a/d enable/disable, a/d channel selection and a/d clock frequency are determined using the two control registers, adcr and acsr.
ht56r64 rev. 1.60 18 may 21, 2012 serial interface registers the device contains two serial interfaces, an spi and an i 2 c interface. the simcon0, simcon1, simar/ simcon2 are the control registers for the serial inter - face function while the simdr is the data register for the serial interface data. port a wake-up register  pawu all pins on port a have a wake-up function enable a low going edge on these pins to wake-up the device when it is in a power down mode. the pins on port a that are used to have a wake-up function are selected using this resister. pull-high resistors  papu, pbpu, pdpu all i/o pins on ports pa, pb and pd, if setup as inputs, can be connected to an internal pull-high resistor. the pins which require a pull-high resistor to be connected are selected using these registers. register  clkmod the device operates using a dual clock system whose mode is controlled using this register. the register con - trols functions such as the clock source, the idle mode enable and the division ratio for the slow clock. lcd registers  lcdctrl, lcdout1, lcdout2 the device contains a fully integrated lcd driver func- tion which can be setup in various configurations allow- ing it to control a wide range of external lcd panels. most of these options are controlled using the lcdctrl register. as some of the lcd segment driv- ing pins can also be setup to be used as cmos oututs, two registers, lcdout1 and lcdout2, are used to select the required function. miscellaneous register  misc the miscellaneous register is used to control two func - tions. the four lower bits are used for the watchdog timer control, while the highest four bits are used to se - lect open drain outputs for pins pa0~pa3. input/output ports holtek microcontrollers offer considerable flexibility on their i/o ports. with the input or output designation of ev - ery pin fully under user program control, pull-high selec - tions for all ports and wake-up selections on certain pins, the user is provided with an i/o structure to meet the needs of a wide range of application possibilities. the device provides 24 bidirectional input/output lines labeled with port names pa, pb and pd. these i/o ports are mapped to the ram data memory with specific ad - dresses as shown in the special purpose data memory table. all of these i/o ports can be used for input and output operations. for input operation, these ports are non-latching, which means the inputs must be ready at the t2 rising edge of instruction  mov a,[m] , where m denotes the port address. for output operation, all the data is latched and remains unchanged until the output latch is rewritten. pull-high resistors many product applications require pull-high resistors for their switch inputs usually requiring the use of an exter - nal resistor. to eliminate the need for these external re - sistors, all i/o pins, when configured as an input have the capability of being connected to an internal pull-high resistor. these pull-high resistors are selected using registers papu, pbpu and pdpu and are implemented using weak pmos transistors. port a wake-up the halt instruction forces the microcontroller into a power down condition which preserves power, a fea - ture that is important for battery and other low-power ap - plications. various methods exist to wake-up the microcontroller, one of which is to change the logic con - dition on one of the port a pins from high to low. after a halt instruction forces the microcontroller into entering a power down condition, the processor will remain in a low-power state until the logic condition of the selected wake-up pin on port a changes from high to low. this function is especially suitable for applications that can be woken up via external switches. each pin on port a can be selected individually to have this wake-up fea- ture using the pawu register. port a open drain function all i/o pins in the device have cmos structures, how- ever port a pins pa0~pa3 can also be setup as open drain structures. this is implemented using the ode0~ode3 bits in the misc register. i/o port control registers each i/o port has its own control register known as pac, pbc, and pdc, to control the input/output configuration. with this control register, each cmos output or input with or without pull-high resistor structures can be re - configured dynamically under software control. each pin of the i/o ports is directly mapped to a bit in its associ - ated port control register. for the i/o pin to function as an input, the corresponding bit of the control register must be written as a 1 . this will then allow the logic state of the input pin to be directly read by instructions. when the corresponding bit of the control register is written as a 0 , the i/o pin will be setup as a cmos out - put. if the pin is currently setup as an output, instructions can still be used to read the output register. however, it should be noted that the program will in fact only read the status of the output data latch and not the actual logic status of the output pin.
ht56r64 rev. 1.60 19 may 21, 2012 pin-shared functions the flexibility of the microcontroller range is greatly en - hanced by the use of pins that have more than one func - tion. limited numbers of pins can force serious design constraints on designers but by supplying pins with multi-functions, many of these difficulties can be over - come. for some pins, the chosen function of the multi-function i/o pins is set by configuration options while for others the function is set by application pro - gram control.  external interrupt inputs the external interrupt pins int0, int1 are pin-shared with the i/o pins pd4, pd5. for applications not re- quiring an external interrupt input, the pin-shared ex- ternal interrupt pin can be used as a normal i/o pin, however to do this, the external interrupt enable bits in the intc0 register must be disabled.  external timer clock input the external timer pins tmr0, tmr1 are pin-shared with the i/o pin pd6, pd7. to configure it to operate as a timer input, the corresponding control bits in the timer control register must be correctly set and the pin must also be setup as an input. note that the original i/o function will remain even if the pin is setup to be used as an external timer input.  pfd output the device contains a pfd function whose single out - put is pin-shared with pa3. the output function of this pin is chosen via a configuration option and remains fixed after the device is programmed. note that the corresponding bit of the port control register, pac.3, must setup the pin as an output to enable the pfd out - put. if the pac port control register has setup the pin as an input, then the pin will function as a normal logic input with the usual pull-high selection, even if the pfd configuration option has been selected.  pwm outputs the device contains four pwm outputs shared with pin pd0~pd3. the pwm output functions are chosen via registers. note that the corresponding bit of the port control register, pdc, must setup the pin as an output to enable the pwm output. if the pdc port con - trol register has setup the pin as an input, then the pin will function as a normal logic input with the usual pull-high selection, even if the pwm registers have been selected.  a/d inputs the device has eight a/d converter inputs. all of these analog inputs are pin-shared with i/o pins on port b. if these pins are to be used as a/d inputs and not as nor - mal i/o pins then the corresponding bits in the a/d converter control register, adcr, must be properly set. there are no configuration options associated with the a/d function. if used as i/o pins, then full pull-high resistor register remain, however if used as a/d inputs then any pull-high resistor selections associated with these pins will be automatically disconnected. i/o pin structures the accompanying diagrams illustrate the i/o pin inter- nal structures. as the exact logical construction of the i/o pin may differ from these drawings, they are supplied as a guide only to assist with the functional understand - ing of the i/o pins. programming considerations within the user program, one of the first things to con - sider is port initialisation. after a reset, all of the i/o data and port control registers will be set high. this means that all i/o pins will default to an input state, the level of which depends on the other connected circuitry and whether pull-high selections have been chosen. if the port control registers, pac, pbc and pdc, are then pro - grammed to setup some pins as outputs, these output pins will have an initial high output value unless the as - sociated port data registers, pa, pb and pd, are first programmed. selecting which pins are inputs and which are outputs can be achieved byte-wide by loading the correct values into the appropriate port control register or by programming individual bits in the port control reg - ister using the  set [m].i and  clr [m].i instructions. note that when using these bit control instructions, a & '  (          4  (  ! 8 6  6  (  ! 8 /         
   !                
        %      ' 6     (  
      / a       6 a  
      ' /     (  
      / a       6 a  
      ' .     (  
      / a       6 a  
      ' 0     (  
      / a       6 a  
      ( ! 6  (  ! 8 .  (  ! 8 0  ( ! /  ( ! .  ( ! 0 pa0~pa3 open drain control  misc
ht56r64 rev. 1.60 20 may 21, 2012         *         (       
          7
 (     7    
           
    
                   
     
   (       
    (     7
 ( i ;  i ( i ;  i & ( (   :   : 7 9 ! 8 b   + ( ! 8 b    ! 8   *      
  ' 6 # 7 9  ' / # 7 9  ' .  ' 0 #  + (  ' 1 #    .  ' 2 #    0  ' 3 b   ' 4  ( 6 #    6 j  ( 0 #    0  ( 1 #  8  6  ( 2 #  8  /  ( 3 #    6  ( 4 #    /      d
    
          ' 6 #  ' / #  ' 0 #  ( 6 #  ( / #  ( . #  ( 0 7 9 # 7 9 #  + ( #    6 #    / #    . #    0  ' 6 j  ' 0     (  
       8  6  f     ( 1      8  /  f     ( 2        6  f     ( 3        /  f     ( 4     pa, pd input/output ports read-modify-write operation takes place. the microcontroller must first read in the data on the entire port, modify it to the required new bit values and then re - write this data back to the output ports. port a has the additional capability of providing wake-up functions. when the device is in the power down mode, various methods are available to wake the device up. one of these is a high to low transition of any of the port a pins. single or multiple pins on port a can be setup to have this function.  /  .  0  1  /  .  0  1  
               f                *      (    read/write timing   )   ) *           ' < 6 b   7 < 6 b   ( < 6       
  / a       6 a  
      ' < / b   7 < / b   ( < /       
  / a       6 a  
      ' < 4 b   7 < 4 b   ( < 4       
  / a       6 a  
      4  "   6  6  "   /  "   4 pull-high resistor register  papu, pbpu, pdpu
ht56r64 rev. 1.60 21 may 21, 2012 & ( (   :      (       
          7
 (     7    
           
    
                   
     
   (       
    (     7
  7 6 # ' 8 6 j  7 4 # ' 8 4 '  . j '  6    ' # (   )        .   /   6    *       '               ( i ;  i ( i ;  i      d
    
         pb input/output ports liquid crystal display (lcd) driver for large volume applications, which incorporate an lcd in their design, the use of a custom display rather than a more expensive character based display reduces costs significantly. however, the corresponding signals required, which vary in both amplitude and time, to drive such a custom display require many special consider- ations for proper lcd operation to occur. the holtek lcd driver function, with its internal lcd signal gener- ating circuitry and various options, will automatically generate these time and amplitude varying signals to provide a means of direct driving and easy interfacing to a range of custom lcds. lcd memory an area of data memory is especially reserved for use by the lcd data. this data area is known as the lcd memory. any data written here will be automatically read by the internal lcd driver circuits, which will in turn automatically generate the necessary lcd driving sig - nals. therefore any data written into the lcd memory will be immediately reflected into the actual lcd display connected to the microcontroller . the start address of the lcd memory is 40h; the end address of the lcd memory is 60h. as the lcd data memory addresses overlap those of the general purpose data memory, the lcd data mem - ory is stored in its own memory data bank, which is dif - ferent from that of the general purpose data memory. the lcd data memory is stored in bank 1. the data memory bank is chosen by using the bank pointer, which is a special function register in the data memory, with the name, bp. when the lowest bit of the bank pointer has the binary value 0 , only the general pur- pose data memory will be accessed, no read or write actions to the lcd memory will take place. to access the lcd memory therefore requires first that bank 1 is selected by setting the lowest bit of the bank pointer to the binary value 1 . after this, the lcd memory can then be accessed by using indirect addressing through the use of memory pointer mp1. with bank 1 selected, then using mp1 to read or write to the memory area, 40h~60h, will result in operations to the lcd memory. directly addressing the lcd memory is not applicable and will result in a data access to the bank 0 general purpose data memory. the diagrams below are based on 33  2, 33  3or32  4 format pixel drive capability lcd panels. the 4-com for - mat will be automatically setup when the 1 / 4 duty control bit is selected while the 3-com format will be automati - cally setup if the 1 / 3 duty control bit is selected.
ht56r64 rev. 1.60 22 may 21, 2012 a               h 6 h 1 6 d 3 6 d  4  3  2  1  0  .  /  6  ! -  6  ! -  0 .    6    /    . 1 / d  ! -  / 1 6 d 3 6 d  4  3  2  1  0  .  /  6  ! -  6  ! -  0 .    6    /    .    0 1 / d  ! -  /  ! -  0 / 2 + d 2 + d  ! -  0 / +        , * -  % . +    * -  % . lcd memory map lcd registers a single lcd control register in the data memory, known as lcdctrl, is used to control the various setup features of the lcd driver. various bits in this reg- ister control functions such as duty type, bias type, bias resistor selection as well as overall lcd enable and dis- able. the lcden bit in the lcdctrl register will only be effective when the device is in the normal, slow or idle mode. if the device is in the sleep mode then the lcd will always be disabled. bits rsel0 and rsel1 select the internal bias resistors to supply the lcd panel with the correct bias voltages. a choice to best match the lcd panel used in the application can be selected also to minimise bias current. the type bit is used to select whether type a or type b lcd control signals are used. $ ( ! 8 7           ! $ ( =       $ ( >  ( * (             4 7  '   @  !  6   ! $ /   ! $ 6 $ ( ! 8 (  @ / 3 6 6 *     
     = / # 0  7
  > b   7  '  k 4 < 2  ' 0 6 6 *     
     = / # 0  7
  > b   7  '  k / 2  ' / 6 6 *     
     = / # 0  7
  > b   7  '  k 1 2  ' 2 6 *     
     = / # 0  7
  > b   7  '  k 5 6  ' 6 6 / / 6 / 6 / (  @ 6 $ (       # 
           / a       6 a  
           8     b     %             $ (  %
       #  f f     
     h $ ( ! 8 h k / # 6                    $ ( 
    %      f f $ (  
     
              ! $ /      ! $ 6      & $ ( / k 1 < 2 & $ (  7
  / a  / # 0  7
  6 a  / # .  7
  8   
      b          h 6 h $ (  (      (  @ /     (  @ 6 $ (      '     7 / a      7 6 a      ' / # .      / # 0      / # 1           )   6 6 / / 6 / 6 / lcd control register  lcdctrl
ht56r64 rev. 1.60 23 may 21, 2012  ( *             6 $ (   $ (  6  4  ! - 6 j  ! - 4                    / a           6 a   ! -        ! -  j  ! - / 2                    / a           6 a   ! -       8   
      b          h 6 h lcd output control register  lcdout1  ( *             ! - / 3 j  ! - . 0                    / a           6 a   ! -        6 $ (  / 3  4 $ (  / 4 $ (  /  $ (  / 5 $ (  . 6 $ (  . / $ (  . . $ (  . 0 lcd output control register  lcdout2 two registers, lcdout1 and lcdout2 are used to determine if the output function of lcd pins seg0~ seg23 are used a lcd segment drivers or cmos out - puts. if used as cmos outputs then the lcd data mem - ory is used to determine the logic level of the cmos output pins. note that as only two bits are used to deter - mine the output function of the seg0~seg7 and seg8~seg15 pins, individual pins from these two groups of pins cannot be chosen to have either a seg- ment or cmos output function. the output function of pins seg16~seg23 can be chosen individually to be either an lcd segment driver or a cmos input. ldc reset function the lcd has an internal reset function that is an or function of the inverted lcden bit in the lcdctrl reg- ister and the sleep function. the lcd reset signal is ac - tive high. the lcdenb signal is the inverse of the lcden bit in the lcdctrl register. relcd= (sleep and idlen=0 ) or lcdenb. ledsel=0 & lcden=1 must be enabled to activate the lcdctrl register function. lcd clock the lcd clock source is the internal clock signal, f sub , divided by 8, using an internal divider circuit. the f sub internal clock is supplied by either the internal 32k_int oscillator or the external rtc oscillator, the choice of which is determined by a configuration option. for proper lcd operation, this arrangement is provided to generate an ideal lcd clock source frequency of 4khz. f sub clock source lcd clock frequency internal 32k_int osc. 4khz external rtc osc. 4khz lcd clock source lcd driver output the number of com and seg outputs supplied by the lcd driver, as well as its biasing and duty selections, are dependent upon the lcd control bits selected. the accompanying table lists the various selections. the bias type, whether c or r type is selected using a con - figuration option. duty driver number bias bias type waveform type 1 / 2 332 1 / 2or 1 / 3 corr type aorb 1 / 3 333 1 / 4 324 lcd selections if the c-type of bias is used then an internal charge pump will be enabled. this charge pump has two volt - age multiplier options selected using a configuration op - tion. note that the c-type bias is not available on the 52-pin qfp package type. the nature of liquid crystal displays require that only ac voltages can be applied to their pixels as the applica - tion of dc voltages to lcd pixels may cause permanent damage. for this reason the relative contrast of an lcd display is controlled by the actual rms voltage applied to each pixel, which is equal to the rms value of the voltage on the com pin minus the voltage applied to the seg pin. this differential rms voltage must be greater than the lcd saturation voltage for the pixel to be on and less than the threshold voltage for the pixel to be off. the requirement to limit the dc voltage to zero and to control as many pixels as possible with a minimum num - ber of connections, requires that both a time and ampli - tude signal is generated and applied to the application lcd. these time and amplitude varying signals are au - tomatically generated by the lcd driver circuits in the
ht56r64 rev. 1.60 24 may 21, 2012 microcontroller. what is known as the duty determines the number of common lines used, which are also known as backplanes or coms. the duty, which is cho - sen by a control bit to have a value of 1 / 2, 1 / 3or1 / 4 and which equates to a com number of 2, 3 and 4 respec - tively, therefore defines the number of time divisions within each lcd signal frame. two types of signal gen - eration are also provided, known as type a and type b, the required type is selected via the type bit in the lcdctrl register. type b offers lower frequency sig - nals, however lower frequencies may introduce flicker - ing and influence display clarity. the accompanying timing diagrams depict the lcd signals generated by the microcontroller for various values of duty and bias. lcd voltage source and biasing the time and amplitude varying signals generated by the lcd driver function require the generation of sev - eral voltage levels for their operation. the number of voltage levels used by the signal depends upon the value of the bias bit in the lcdctrl register. the de - vice can have either r type or c type biasing selected via a configuration option. selecting the c type biasing will enable an internal charge pump whose multiplying ration can be selected using an additional configuration option. for r type biasing an external lcd voltage source must be supplied on pin vlcd1 to generate the internal bias - ing voltages. this could be the microcontroller power supply or some other voltage source. for the r type 1 / 2 bias selection, three voltage levels vss, va and vb are utilised. the voltage va is equal to the externally sup - plied voltage source applied to pin vlcd1. vb is gener - ated internally by the microcontroller and will have a value equal to vlcd1 / 2. for the r type 1 / 3 bias selec - tion, four voltage levels vss, va, vb and vc are uti - lised. the voltage va is equal to vlcd1, vb is equal to vlcd12 / 3 while vc is equal to vlcd1 1 / 3. in addition to selecting 1 / 2or1 / 3 bias, several values of bias resis - tor can be chosen using bits in the lcdctrl register. different values of internal bias resistors can be se - lected using the rsel0 and resel1 bits in the lcdctrl register. this along with the voltage on pin vlcd1 will determine the bias current. the connection to the vmax pin depends upon the voltage that is ap - plied to vlcd1. if the vdd voltage is greater than the voltage applied to the vlcd1 pin then the vmax pin should be connected to vdd, otherwise the vmax pin should be connected to pin vlcd1. note that no exter - nal capacitors or resistors are required to be connected if r type biasing is used. & $ ( /   & $ ( / & ' & 7 $ (   %        &  = k & $ ( /  . # 0 > = k & $ ( /  / # 0 > = k & $ ( / > $ (   #  f f   & ' & 7 $ (   %        = k & $ ( /  / # . > = k & $ ( / > $ (   #  f f &  ' : &  ' : 6 < /  + & / 6 < /  + & / r type bias voltage levels (  % !    ,   "   , (  "    -  ! & $ ( / 6 < /  + 6 < /  + 6 < /  + $ (   %               / . & / & $ ( . & ' & 7 & = k & $ ( /  / < 2 > = k & $ ( / > = k & $ ( /   < 2 &       f    / # 0  7
      > &  ' : (  % !       "    (  "    -  ! 6 < /  +        / 6 < /  + 6 < /  + . & / & $ ( . & $ ( / & ' & 7 = k & $ ( / > = k & $ ( /  6 < 2 > &  ' : $ (   %        c type bias voltage levels
ht56r64 rev. 1.60 25 may 21, 2012 condition vmax connection vdd > vlcd1 connect vmax to vdd otherwise connect vmax to vlcd1 r type bias current vmax connection for c type biasing an external lcd voltage source must also be supplied on pin vlcd1 to generate the internal biasing voltages. the c type biasing scheme uses an in - ternal charge pump circuit, which in the case of the 1 / 3 bias selection can generate voltages higher than what is supplied on vlcd1. this feature is useful in applica - tions where the microcontroller supply voltage is less than the supply voltage required by the lcd. the exter - nal lcd power supply should be connected to pin vlcd1 and a filter capacitor connected to pin vlcd2. an additional charge pump capacitor must also be con - nected between pins c1 and c2 to generate the neces - sary voltage levels. for the c type 1 / 2 bias selection, three voltage levels vss, va and vb are utilised. the voltage va is generated internally and has a value of vlcd1. vb will have a value equal to va  0.5. for the c type 1 / 2 bias configuration vc is not used. for the c type 1/3 bias selection, four voltage levels vss, va, vb and vc are utilised. the voltage va is gen- erated internally and has a value of vlcd1  1.5. vb will have a value equal to va  2 / 3 and vc will have a value equal to va  1 / 3. the connection to the vmax pin de- pends upon the bias and the voltage that is applied to vlcd1, the details are shown in the table. note that c type biasing is not available on the 52-pin qfp package device types. on these package types, pins c1, c2 and vlcd2 are not provided. it is recommended that a 0.1 f capacitor is connected between the v1 pin and ground on the 52-pin qfp package types. it is extremely important to ensure that these charge pump generated internal voltages do not exceed the maximum vdd voltage of 5.5v. note that the c-type bias type is not available on the 52-pin qfp package type. biasing type vmax connection 1 / 3 bias vdd vlcd11.5 connect vmax to vdd otherwise connect vmax to v1 1 / 2 bias vdd vlcd1 connect vmax to vdd otherwise connect vmax to vlcd1 c type biasing vmax connection programming considerations certain precautions must be taken when programming the lcd. one of these is to ensure that the lcd memory is properly initialised after the microcontroller is pow - ered on. like the general purpose data memory, the contents of the lcd memory are in an unknown condi - tion after power-on. as the contents of the lcd memory will be mapped into the actual lcd, it is important to in- itialise this memory area into a known condition soon af- ter applying power to obtain a proper display pattern. consideration must also be given to the capacitive load of the actual lcd used in the application. as the load presented to the microcontroller by lcd pixels can be generally modeled as mainly capacitive in nature, it is   6          8   /          8 '            8 & ' & 7  &    & ' & 7  &    & ' & 7  &      6    /  '            + + & ' & 7  &    & ' & 7  &    & ' & 7  &    /    " $ !   "    # &  0    6 b    /  '                 & ' & 7  &    & ' & 7  &    /  +    * -   #          #     &  0  lcd driver output  type a - 1 / 2 duty, 1 / 2 bias note for 1 / 2 bias, va=vlcd1, vb=vlcd1 1 / 2 for both r and c type.
ht56r64 rev. 1.60 26 may 21, 2012 important that this is not excessive, a point that is partic - ularly true in the case of the com lines which may be connected to many lcd pixels. the accompanying dia - gram depicts the equivalent circuit of the lcd. with such a frequency chosen, the microcontroller inter - nal lcd driver circuits will ensure that the appropriate lcd driving signals are generated to obtain a suitable lcd frame frequency. one additional consideration that must be taken into ac - count is what happens when the microcontroller enters a halt condition. the  lcden control bit in the lcdctrl register permits the lcd to be powered off to reduce power consumption. if lcden =0 is selected, the driving signals to the lcd will cease, producing a blank display pattern but reducing any power consump - tion associated with the lcd. after power-on, note that as the lcden bit in the lcdctrl register will be cleared to zero, the lcd func - tion will be disabled. the following timing diagrams depict the lcd signals generated by the microcontroller for various values of duty and bias.   6   /   .   0  ! - 6  ! - /  ! - .  ! - lcd panel equivalent circuit /    " $ !   "    # &  0  * -   #          #     &  0    6 b    / b    .  '                   6    /    .  '            + +   6          8   /          8   .          8   6 b  /          8   6 b  .          8   / b  .          8 '            8 & ' & 7  &    & ' & 7  &    & ' & 7  &    & ' & 7  &    & ' & 7  &    & ' & 7  &    & ' & 7  &    & ' & 7  &    & ' & 7  &    & ' & 7  &    & ' & 7  &    & ' & 7  &    & ' & 7  &    /  +    lcd driver output  type a- 1 / 3 duty, 1 / 2 bias note: for 1 / 2 bias, the va=vlcd1, vb=vlcd1 1 / 2 for both r and c type.
ht56r64 rev. 1.60 27 may 21, 2012 & '  & 7 & &   /  +    & '  & 7 & &   & '  & 7 & &   & '  & 7 & &   & '  & 7 & &   & '  & 7 & &   & '  & 7 & &   & '  & 7 & &   & '  & 7 & &   & '  & 7 & &     6    /    .  '            + +   6          8   0   /          8   .          8 =        
 
       
    >   6 b  /          8   0          8 /    " $ !   "    # &  0  * -   #          #     &  0    6 b    / b    . b    0  '                 & '  & 7 & &   & '  & 7 & &   & '  & 7 & &     6 b  .          8 & '  & 7 & &     6 b  0          8 & '  & 7 & &   '            8 lcd driver output  type a - 1 / 4 duty, 1 / 3 bias note: for 1 / 3 r type bias, the va=vlcd1, vb=vlcd1 2 / 3 and vc=vlcd1 1 / 3. for 1 / 3 c type bias, the va=vlcd1  1.5, vb=vlcd1 and vc=vlcd11 / 2.
ht56r64 rev. 1.60 28 may 21, 2012 & '  & 7 & &   /  +    & '  & 7 & &   & '  & 7 & &   & '  & 7 & &   & '  & 7 & &   & '  & 7 & &   & '  & 7 & &   & '  & 7 & &   & '  & 7 & &     6    /    .  '            + +   6          8   /          8   .          8   6 b  .          8   6 b  /          8 & '  & 7 & &     / b  .          8 & '  & 7 & &   '            8 /    " $ !   "    # &  0  * -   #          #     &  0    6 b    / b    .  '                 & '  & 7 & &   & '  & 7 & &   lcd driver output  type a - 1 / 3 duty, 1 / 3 bias note: for 1 / 3 r type bias, the va=vlcd1, vb=vlcd1 2 / 3 and vc=vlcd1 1 / 3. for 1 / 3 c type bias, the va=vlcd1  1.5, vb=vlcd1 and vc=vlcd11 / 2.
ht56r64 rev. 1.60 29 may 21, 2012 & ' & 7 &     6   /   f f   6           f f   f f    f f   /           f f   f f   f f   6         f f  f f  f f  f f   f f   f f   f f  f f  f f  f f  f f f f  f f f f  f f f f  f f f f & ' & 7 &   & ' & 7 &   & ' & 7 &   & ' & 7 &     f f   f f   f f  f f lcd driver output  type b  1 / 2 duty, 1 / 2 bias note: for 1 / 2 bias, the va=vlcd, vb=vlcd1 1 / 2 for both r and c type.
ht56r64 rev. 1.60 30 may 21, 2012 timer/event counters the provision of timers form an important part of any microcontroller, giving the designer a means of carrying out time related functions. the devices contain one 8-bit and one 16-bit count-up timer. as each timer has three different operating modes, they can be configured to op - erate as a general timer, an external event counter or as a pulse width measurement device. the provision of a prescaler to the clock circuitry of the 8-bit timer/event counter also gives added range to this timer. there are two types of registers related to the timer/event counters. the first are the registers that contain the actual value of the timer/event counter and into which an initial value can be preloaded. reading from these registers retrieves the contents of the timer/event counter. the second type of associated register is the timer control register which defines the timer options and determines how the timer/event counter is to be used. the timer/event counters can have the their clock configured to come from an internal clock source. in addition, their clock source can also be configured to come from an external timer pin. configuring the timer/event counter input clock source the internal timer
s clock can originate from various sources. the system clock source is used when the timer/event counter is in the timer mode or in the pulse width measurement mode. for timer/event counter 0 this internal clock source is f sys which is also divided by a prescaler, the division ratio of which is conditioned by the timer control register, tmr0c, bits t0psc0~ t0psc2. for timer/event counter 1 this internal clock source can be chosen from a combination of internal clocks using a configuration option and the t1s bit in the tmr1c register. an external clock source is used when the timer is in the event counting mode, the clock source being provided on an external timer pin tmr0 or tmr1, depending upon which timer is used. depending upon the condition of the t0e or t1e bit, each high to low, or low to high transition on the external timer pin will increment the counter by one. timer registers  tmr0, tmr1l, tmr1h the timer registers are special function registers located in the special purpose data memory and is the place where the actual timer value is stored. for the 8-bit timer/event counter 0, this register is known as tmr0. for 16-bit timer/event counter 1, the timer registers are known as tmr1l and tmr1h. the value in the timer registers in - creases by one each time an internal clock pulse is re - ceived or an external transition occurs on the external timer pin. the timer will count from the initial value loaded by the preload register to the full count of ffh for the 8-bit timer or ffffh for the 16-bit timer at which point the timer overflows and an internal interrupt signal is generated. the timer value will then be reset with the initial preload register value and continue counting. to achieve a maximum full range count of ffh for the 8-bit timer or ffffh for the 16-bit timer, the preload reg - isters must first be cleared to all zeros. it should be noted that after power-on, the preload register will be in an unknown condition. note that if the timer/event counter is switched off and data is written to its preload registers, this data will be immediately written into the actual timer registers. however, if the timer/event counter is enabled and counting, any new data written into the preload data registers during this period will re- main in the preload registers and will only be written into the timer registers the next time an overflow occurs. for the 16-bit timer/event counter which has both low byte and high byte timer registers, accessing these reg - isters is carried out in a specific way. it must be noted when using instructions to preload data into the low byte timer register, namely tmr1l, the data will only be placed in a low byte buffer and not directly into the low byte timer register. the actual transfer of the data into      
                         
   ?  / 
   ?  . 
   ?  8 
   ?  8  ?  / timer mode timing chart 
  ? . ! "       ! )        
        
  ? 0 
  ? / event counter mode timing chart
ht56r64 rev. 1.60 31 may 21, 2012 the low byte timer register is only carried out when a write to its associated high byte timer register, namely tmr1h, is executed. on the other hand, using instruc - tions to preload data into the high byte timer register will result in the data being directly written to the high byte timer register. at the same time the data in the low byte buffer will be transferred into its associated low byte timer register. for this reason, the low byte timer regis - ter should be written first when preloading data into the 16-bit timer registers. it must also be noted that to read the contents of the low byte timer register, a read to the high byte timer register must be executed first to latch the contents of the low byte timer register into its associ - ated low byte buffer. after this has been done, the low byte timer register can be read in the normal way. note that reading the low byte timer register will result in read - ing the previously latched contents of the low byte buffer and not the actual contents of the low byte timer register. timer control registers  tmr0c, tmr1c the flexible features of the holtek microcontroller timer/event counters enable them to operate in three different modes, the options of which are determined by the contents of their respective control register. it is the timer control register together with its corre - sponding timer registers that control the full operation of the timer/event counters. before the timers can be used, it is essential that the appropriate timer control register is fully programmed with the right data to en - sure its correct operation, a process that is normally car - ried out during program initialisation. to choose which of the three modes the timer is to oper - ate in, either in the timer mode, the event counting mode or the pulse width measurement mode, bits 7 and 6 of the timer control register, which are known as the bit pair t0m1/t0m0 or t1m1/t1m0 respectively, depend - ing upon which timer is used, must be set to the required logic levels. the timer-on bit, which is bit 4 of the timer control register and known as t0on or t1on, depend - ing upon which timer is used, provides the basic on/off control of the respective timer. setting the bit high allows the counter to run, clearing the bit stops the counter. for timers that have prescalers, bits 0~2 of the timer con - trol register determine the division ratio of the input clock prescaler. the prescaler bit settings have no effect if an external clock source is used. if the timer is in the event count or pulse width measurement mode, the ac - tive transition edge level type is selected by the logic      6 
  # ! )                    6  8           
    
  # ! )        (     7          )   f   %              . 4                 6   . j  6   6 = / # / j / # / .  >   7
  
  # ! )          6  /  6  6   f  @   + ( 6   6 ! +
    +
      #  f f  f
    
   
 timer/event counter 0 structure    /  / ! 
  # ! )                   / 3  7
           
    (     7          )   f   %           $  %  7    7  f f    /  /  /  6  /  8 d
   7    $  %  7    / 3  7
  
  # ! )          + ( /    .   /    :    f  @  # 1   :    f   7 ! "       f          0 . ;   8   f
    
  
 +
    +
      #  f f  f
    
   
 timer/event counter 1 structure   :   + ( 6  + ( /  f
    
  
  + (
ht56r64 rev. 1.60 32 may 21, 2012       1 2  #  (  - #    (  #    $          &   (  4 ! )           
)             / a        f   
      6 a        

        6 ! 6  8  6  6 6  / 
                      6   . 6 6 6 6 / / / /  6  6   .  6   /  6   6  6   / 6 6 / / 6 6 / /  6   6 6 / 6 / 6 / 6 / 
            / a /      / a .      / a 1      / a       / a / 3      / a 0 .      / a 3 1      / a / .  
  # ! )            
       / a       6 a  
         
            6  / 6 6 / /  6  6 6 / 6 /        ) 
      )              
           %
                      
               
)             / a          
    

      b        f   
      6 a          
    f   
      b        

       8   
      b          h 6 h timer/event counter control register tmr0c  4  / !  /  8  /  6  /  /  6       1 2  #  (  - #    (  #    $          &   ( 8   
      b          h 6 h ! )           
)             / a        f   
      6 a        

            
               
)             / a          
    

      b        f   
      6 a          
    f   
      b        

      
  # ! )            
       / a       6 a  
      /  / 6 6 / /  /  6 6 / 6 /        ) 
      )             
           %
                    
           
     *       / a  f   7  =       0 . ;   > 6 a  f  @  # 1  /  timer/event counter 1 control register tmr1c
ht56r64 rev. 1.60 33 may 21, 2012 level of bit 3 of the timer control register which is known as t0e or t1e depending upon which timer is used. an additional t1s bit in the tmr1c register is used to determine the clock source for timer/event counter 1. configuring the timer mode in this mode, the timer/event counter can be utilised to measure fixed time intervals, providing an internal inter - rupt signal each time the timer/event counter over - flows. to operate in this mode, the operating mode select bit pair, t0m1/t0m0 or t1m1/t1m0, in the timer control register must be set to the correct value as shown. control register operating mode select bits for the timer mode bit7 bit6 10 in this mode the internal clock, f sys , is used as the inter - nal clock for 8-bit timer/event counter 0 and f sub or f sys /4 is used as the internal clock for 16-bit timer/event counter 1. however, the clock source, f sys , for 8-bit timer is further divided by a prescaler, the value of which is determined by the prescaler rate select bits t0psc2~t0psc0, which are bits 2~0 in the timer con - trol register. after the other bits in the timer control register have been setup, the enable bit t0on or t1on, which is bit 4 of the timer control register, can be set high to enable the timer/event counter to run. each time an internal clock cycle occurs, the timer/event counter increments by one. when it is full and overflows, an interrupt signal is generated and the timer/event counter will reload the value already loaded into the preload register and continue counting. the interrupt can be disabled by ensuring that the timer/event counter interrupt enable bit in the interrupt control register, intc0, is reset to zero. configuring the event counter mode in this mode, a number of externally changing logic events, occurring on the external timer pin, can be re - corded by the timer/event counter. to operate in this mode, the operating mode select bit pair, t0m1/t0m0 or t1m1/t1m0, in the timer control register must be set to the correct value as shown. control register operating mode select bits for the event counter mode bit7 bit6 01 in this mode, the external timer pin, tmr0 or tmr1, is used as the timer/event counter clock source, however it is not divided by the internal prescaler. after the other bits in the timer control register have been setup, the enable bit t0on or t1on, which is bit 4 of the timer control register, can be set high to enable the timer/event counter to run. if the active edge select bit t0e or t1e, which is bit 3 of the timer control register, is low, the timer/event counter will increment each time the external timer pin receives a low to high transition. if the active edge select bit is high, the counter will incre - ment each time the external timer pin receives a high to low transition. when it is full and overflows, an interrupt signal is generated and the timer/event counter will re - load the value already loaded into the preload register and continue counting. the interrupt can be disabled by ensuring that the timer/event counter interrupt enable bit in the interrupt control register, intc0, is reset to zero. as the external timer pin is shared with an i/o pin, to en - sure that the pin is configured to operate as an event counter input pin, two things have to happen. the first is to ensure that the operating mode select bits in the timer control register place the timer/event counter in the event counting mode, the second is to ensure that the port control register configures the pin as an input. it should be noted that in the event counting mode, even if the microcontroller is in the power down mode, the timer/event counter will continue to record externally changing logic events on the timer input pin. as a result when the timer overflows it will generate a timer interrupt and corresponding wake-up source. ? / ? . ? 0 ? 1 
  ! "          
     6  8 b   /  8 b   .  8      0  8 = %
    6 ! b   / ! b   . ! b   0 ! k 6 >                    
                      
            )     f   
        f   / < pulse width measure mode timing chart
ht56r64 rev. 1.60 34 may 21, 2012 configuring the pulse width measurement mode in this mode, the timer/event counter can be utilised to measure the width of external pulses applied to the ex - ternal timer pin. to operate in this mode, the operating mode select bit pair, t0m1/t0m0 or t1m1/t1m0, in the timer control register must be set to the correct value as shown. control register operating mode select bits for the pulse width measurement mode bit7 bit6 11 in this mode the internal clock, f sys , is used as the inter - nal clock for 8-bit timer/event counter 0 and f sub or f sys /4 is used as the internal clock for 16-bit timer/event counter 1. however, the clock source, f sys , for 8-bit timer is further divided by a prescaler, the value of which is determined by the prescaler rate select bits t0psc2~t0psc0, which are bits 2~0 in the timer con - trol register. after the other bits in the timer control register have been setup, the enable bit t0on or t1on, which is bit 4 of the timer control register, can be set high to enable the timer/event counter, however it will not actually start counting until an active edge is re - ceived on the external timer pin. if the active edge select bit t0e or t1e, which is bit 3 of the timer control register, is low, once a high to low transition has been received on the external timer pin, tmr0 or tmr1, the timer/event counter will start counting until the external timer pin returns to its original high level. at this point the enable bit will be automati- cally reset to zero and the timer/event counter will stop counting. if the active edge select bit is high, the timer/event counter will begin counting once a low to high transition has been received on the external timer pin and stop counting when the external timer pin re - turns to its original low level. as before, the enable bit will be automatically reset to zero and the timer/event counter will stop counting. it is important to note that in the pulse width measurement mode, the enable bit is automatically reset to zero when the external control signal on the external timer pin returns to its original level, whereas in the other two modes the enable bit can only be reset to zero under program control. the residual value in the timer/event counter, which can now be read by the program, therefore represents the length of the pulse received on the external timer pin. as the enable bit has now been reset, any further transitions on the external timer pin will be ignored. not until the enable bit is again set high by the program can the timer begin further pulse width measurements. in this way, single shot pulse measurements can be easily made. it should be noted that in this mode the timer/event counter is controlled by logical transitions on the exter - nal timer pin and not by the logic level. when the timer/event counter is full and overflows, an interrupt signal is generated and the timer/event counter will re - load the value already loaded into the preload register and continue counting. the interrupt can be disabled by ensuring that the timer/event counter interrupt enable bit in the interrupt control register, intc, is reset to zero. as the external timer pin is shared with an i/o pin, to en - sure that the pin is configured to operate as a pulse width measurement pin, two things have to happen. the first is to ensure that the operating mode select bits in the timer control register place the timer/event coun - ter in the pulse width measurement mode, the second is to ensure that the port control register configures the pin as an input. programmable frequency divider  pfd the programmable frequency divider provides a means of producing a variable frequency output suitable for applications requiring a precise frequency generator. the pfd output is pin-shared with the i/o pin pa3. the pfd function is selected via configuration option, how- ever, if not selected, the pin can operate as a normal i/o pin. the clock source for the pfd circuit can originate from either the timer 0 or timer 1 overflow signal selected via configuration option. the output frequency is controlled by loading the required values into the timer registers and prescaler registers to give the required division ra - tio. the timer will begin to count-up from this preload regis ter value until full, at which point an overflow signal is generated, causing the pfd output to change state. the timer will then be automatically reloaded with the preload register value and continue counting-up. 
    )   f   %  + (    *  ' 0  (     + (            ' 0 pfd output control
ht56r64 rev. 1.60 35 may 21, 2012 for the pfd output to function, it is essential that the corre - sponding bit of the port a control register pac bit 3 is setup as an output. if setup as an input the pfd output will not function, however, the pin can still be used as a normal in - put pin. the pfd output will only be activated if bit pa3 is set to  1  . this output data bit is used as the on/off control bit for the pfd output. note that the pfd output will be low if the pa3 output data bit is cleared to  0  . using this method of frequency generation, and if a crystal oscillator is used for the system clock, very pre - cise values of frequency can be generated. prescaler bits t0psc0~t0psc2 of the tmr0c register can be used to define the pre-scaling stages of the internal clock sources of the timer/event counter 0. the timer/event counter overflow signal can be used to generate signals for the pfd and timer interrupt. i/o interfacing the timer/event counter, when configured to run in the event counter or pulse width measurement mode, re - quire the use of the external pin for correct operation. as this pin is a shared pin it must be configured correctly to ensure it is setup for use as a timer/event counter input and not as a normal i/o pin. this is implemented by en- suring that the mode select bits in the timer/event counter control register, select either the event counter or pulse width measurement mode. additionally the port control register must be set high to ensure that the pin is setup as an input. any pull-high resistor on this pin will remain valid even if the pin is used as a timer/event counter input. timer/event counter pins internal filter the external timer/event counter pins are connected to an internal filter to reduce the possibility of unwanted event counting events or inaccurate pulse width mea - surements due to adverse noise or spikes on the exter - nal timer/event counter input signal. as this internal filter circuit will consume a limited amount of power, a configuration option is provided to switch off the filter function, an option which may be beneficial in power sensitive applications, but in which the integrity of the in - put signal is high. care must be taken when using the fil - ter on/off configuration option as it will be applied not only to both external timer/event counter pins but also to the external interrupt input pins. individual timer/event counter or external interrupt pins cannot be selected to have a filter on/off function. programming considerations when configured to run in the timer mode, the internal system clock is used as the timer clock source and is therefore synchronised with the overall operation of the microcontroller. in this mode when the appropriate timer register is full, the microcontroller will generate an inter - nal interrupt signal directing the program flow to the re - spective internal interrupt vector. for the pulse width measurement mode, the internal system clock is also used as the timer clock source but the timer will only run when the correct logic condition appears on the external timer input pin. as this is an external event and not syn - chronized with the internal timer clock, the microcontroller will only see this external event when the next timer clock pulse arrives. as a result, there may be small differences in measured values requiring pro - grammers to take this into account during programming. the same applies if the timer is configured to be in the event counting mode, which again is an external event and not synchronised with the internal system or timer clock. when the timer/event counter is read, or if data is writ - ten to the preload register, the clock is inhibited to avoid errors, however as this may result in a counting error, this should be taken into account by the programmer. care must be taken to ensure that the timers are properly in - itialised before using them for the first time. the associ - ated timer enable bits in the interrupt control register must be properly set otherwise the internal interrupt associated with the timer will remain inactive. the edge select, timer mode and clock source control bits in timer control regis- ter must also be correctly set to ensure the timer is prop- erly configured for the required application. it is also important to ensure that an initial value is first loaded into the timer registers before the timer is switched on; this is because after power-on the initial values of the timer reg- isters are unknown. after the timer has been initialised the timer can be turned on and off by controlling the en- able bit in the timer control register. note that setting the timer enable bit high to turn the timer on, should only be executed after the timer mode bits have been properly setup. setting the timer enable bit high together with a mode bit modification, may lead to improper timer oper - ation if executed as a single timer control register byte write instruction. when the timer/event counter overflows, its corre - sponding interrupt request flag in the interrupt control register will be set. if the timer interrupt is enabled this will in turn generate an interrupt signal. however irre - spective of whether the interrupts are enabled or not, a timer/event counter overflow will also generate a wake-up signal if the device is in a power-down condi - tion. this situation may occur if the timer/event counter is in the event counting mode and if the external signal continues to change state. in such a case, the timer/event counter will continue to count these exter - nal events and if an overflow occurs the device will be woken up from its power-down condition. to prevent such a wake-up from occurring, the timer interrupt re - quest flag should first be set high before issuing the halt instruction to enter the power down mode.
ht56r64 rev. 1.60 36 may 21, 2012 timer program example this program example shows how the timer/event counter registers are setup, along with how the interrupts are en - abled and managed. note how the timer/event counter is turned on, by setting bit 4 of the timer control register. the timer/event counter can be turned off in a similar way by clearing the same bit. this example program sets the timer/event counter to be in the timer mode, which uses the internal system clock as the clock source. org 04h ; external interrupt vector reti org 08h ; timer/event counter 0 interrupt vector jmp tmrint ; jump here when the timer/event counter 0 overflows : org 20h ; main program ;internal timer/event counter 0 interrupt routine tmrint: : ; timer/event counter 0 main program placed here : reti : : begin: ;setup timer 0 registers mov a,09bh ; setup timer 0 preload value mov tmr0,a; mov a,081h ; setup timer 0 control register mov tmr0c,a ; timer mode and prescaler set to /2 ; setup interrupt register mov a,009h ; enable master interrupt and timer interrupt mov int0c,a set tmr0c.4 ; start timer/event counter 0 - note mode bits must be previously setup
ht56r64 rev. 1.60 37 may 21, 2012 pulse width modulator the device contains four pulse width modulation, pwm, outputs. useful for such applications such as mo - tor speed control, the pwm function provides an output with a fixed frequency but with a duty cycle that can be varied by setting particular values into the correspond - ing pwm register. channel pwm mode output pin register names 1 8+4 pd0 pwm0l pwm0h 2 8+4 pd1 pwm1l pwm1h 3 8+4 pd2 pwm2l pwm2h 4 8+4 pd3 pwm3l pwm3h pwm overview four register pairs, located in the data memory are as - signed to the pulse width modulator and are known as the pwm registers. it is in each register pair that the 12-bit value, which represents the overall duty cycle of one modulation cycle of the output waveform, should be placed. the pwm registers also contain the enable/dis- able control bit for the pwm outputs. to increase the pwm modulation frequency, each modulation cycle is modulated into sixteen individual modulation sub-sections, known as the 8+4 mode. note that it is only necessary to write the required modulation value into the corresponding pwm register as the subdivision of the waveform into its sub-modulation cycles is imple- mented automatically within the microcontroller hard - ware. the pwm clock source is the system clock f sys . this method of dividing the original modulation cycle into a further 16 sub-cycles enables the generation of higher pwm frequencies, which allow a wider range of applications to be served. as long as the periods of the generated pwm pulses are less than the time constants of the load, the pwm output will be suitable as such long time constant loads will average out the pulses of the pwm output. the difference between what is known as the pwm cycle frequency and the pwm modulation fre - quency should be understood. as the pwm clock is the system clock, f sys , and as the pwm value is 12-bits wide, the overall pwm cycle frequency is f sys /4096. however, when in the 8+4 mode of operation, the pwm modulation frequency will be f sys /256. 8+4 pwm mode modulation each full pwm cycle, as it is 12-bits wide, has 4096 clock periods. however, in the 8+4 pwm mode, each pwm cy - cle is subdivided into sixteen individual sub-cycles known as modulation cycle 0 ~ modulation cycle 15, denoted as  i  in the table. each one of these sixteen sub-cycles con - tains 256 clock cycles. in this mode, a modulation fre - quency increase of sixteen is achieved. the 12-bit pwm register value, which represents the overall duty cycle of the pwm waveform, is divided into two groups. the first group which consists of bit4~bit11 is denoted here as the dc value. the second group which consists of bit0~bit3 is known as the ac value. in the 8+4 pwm mode, the duty cycle value of each of the two modulation sub-cycles is shown in the following table. parameter ac (0~15) dc (duty cycle) modulation cycle i (i=0~15) i ac dc+1 256 i ac dc 256 8+4 mode modulation cycle values the accompanying diagram illustrates the waveforms associated with the 8+4 mode of pwm operation. it is important to note how the single pwm cycle is subdi - vided into 16 individual modulation cycles, numbered 0~15 and how the ac value is related to the pwm value. pwm output control pwm modulation frequency pwm cycle frequency pwm cycle duty f sys /256 f sys /4096 (pwm register value)/4096 the four pwm0~pwm3 outputs are shared with pins pd0~pd3. to operate as a pwm output and not as an i/o pin, bit 0 of the relevant pwm register bit must be set high. a zero must also be written to the corresponding bit in the pdc port control register, to ensure that the pwm0 output pin is setup as an output. after these two initial steps have been carried out, and of course after the required pwm 12-bit value has been written into the pwm register pair register, writing a 1 to the corre - sponding pd data register will enable the pwm data to appear on the pin. writing a 0 to the bit will disable the pwm output function and force the output low. in this way, the port d data output register bits, can also be used as an on/off control for the pwm function. note that if the enable bit in the pwm register is set high to enable the pwm function, but a 1 has been written to its corresponding bit in the pdc control register to con - figure the pin as an input, then the pin can still function as a normal input line, with pull-high resistor selections.
ht56r64 rev. 1.60 38 may 21, 2012 3 &           4  6      #  f f       / a           6 a   #  
      8   
      b          h 6 h     '  &     
   6 j 0     (  &     
   1 j / /    ! 8 6 0 /.  4  6  / / 5/ 6 4 3 2 1    6 $ j    0 $ $  %  7       
        6 d j    0 d d
   7       
     pwm register pairs 8+4 pwm mode pwm programming example the following sample program shows how the pwm output is setup and controlled. mov a,64h ; setup pwm0 value to 1600 decimal which is 640h mov pwm0h,a ; setup pwm0h register value clr pwm0l ; setup pwm0l register value clr pdc.0 ; setup pin pd0 as an output set pwm0en ; set the pwm0 enable bit set pd.0 ; enable the pwm0 output :: :: clr pd.0 ; pwm0 output disabled  pd0 will remain low
ht56r64 rev. 1.60 39 may 21, 2012 analog to digital converter the need to interface to real world analog signals is a common requirement for many electronic systems. however, to properly process these signals by a microcontroller, they must first be converted into digital signals by a/d converters. by integrating the a/d con - version electronic circuitry into the microcontroller, the need for external components is reduced significantly with the corresponding follow-on benefits of lower costs and reduced component space requirements. a/d overview the device contains an 8-channel analog to digital con - verter which can directly interface to external analog sig - nals, such as that from sensors or other control signals and convert these signals directly into either a 12-bit dig - ital value. input channels conversion bits input pins 8 12 pb0~pb7 the accompanying block diagram shows the overall in - ternal structure of the a/d converter, together with its associated registers. a/d converter data registers  adrl, adrh the device, which has an internal 12-bit a/d converter, requires two data registers, a high byte register, known as adrh, and a low byte register, known as adrl. after the conversion process takes place, these registers can be directly read by the microcontroller to obtain the digit- ised conversion value. only the high byte register, adrh, utilises its full 8-bit contents. the low byte regis- ter utilises only 4 bit of its 8-bit contents as it contains only the lowest bits of the 12-bit converted value. in the following table, d0~d11 is the a/d conversion data result bits. register bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 adrl d3 d2 d1 d0  adrh d11 d10 d9 d8 d7 d6 d5 d4 a/d data registers a/d converter control registers  adcr, acsr to control the function and operation of the a/d con - verter, two control registers known as adcr and acsr are provided. these 8-bit registers define functions such as the selection of which analog channel is con - nected to the internal a/d converter, which pins are used as analog inputs and which are used as normal i/os, the a/d clock source as well as controlling the start function and monitoring the a/d converter end of con - version status. the acs2~acs0 bits in the adcr register define the channel number. as the device contains only one actual analog to digital converter circuit, each of the individual 8 analog inputs must be routed to the converter. it is the function of the acs2~acs0 bits in the adcr register to determine which analog channel is actually connected to the internal a/d converter. the adcr control register also contains the pcr2~pcr0 bits which determine which pins on port b are used as analog inputs for the a/d converter and which pins are to be used as normal i/o pins. if the 3-bit address on pcr2~pcr0 has a value of  111  , then all eight pins, namely an0~an7 will all be set as analog in- puts. note that if the pcr2~pcr0 bits are all set to zero, then all the port b pins will be setup as normal i/os and the internal a/d converter circuitry will be powered off to reduce the power consumption.    * (
)
     8 '      
    ' (  7 6 # ' 8 6  7 / # ' 8 /  7 4 # ' 8 4 ' # (    f      &       ' (  $ ' (  d ' # (  (      
       6 j   . ' (  6 j ' (  .   '   !  7 ' (    
    
  f
    
 7
            7
        7
 !    f  )   
  7
 ' &   ' # (  -     ' & ( ( ' # (    

)     %        ' (  8 7  7
 ' # (  !     f  @  a/d converter structure
ht56r64 rev. 1.60 40 may 21, 2012 the start bit in the adcr register is used to start and reset the a/d converter. when the microcontroller sets this bit from low to high and then low again, an analog to digital conversion cycle will be initiated. when the start bit is brought from low to high but not low again, the eocb bit in the adcr register will be set to a 1 and the analog to digital converter will be reset. it is the start bit that is used to control the overall on/off opera- tion of the internal analog to digital converter. the eocb bit in the adcr register is used to indicate when the analog to digital conversion process is com - plete. this bit will be automatically set to 0 by the microcontroller after a conversion cycle has ended. in addition, the corresponding a/d interrupt request flag will be set in the interrupt control register, and if the inter - rupts are enabled, an appropriate internal interrupt sig - nal will be generated. this a/d internal interrupt signal will direct the program flow to the associated a/d inter - nal interrupt address for processing. if the a/d internal interrupt is disabled, the microcontroller can be used to poll the eocb bit in the adcr register to check whether it has been cleared as an alternative method of detect - ing the end of an a/d conversion cycle. the clock source for the a/d converter, which originates from the system clock f sys , is first divided by a division ratio, the value of which is determined by the adcs2, adcs1 and adcs0 bits in the acsr register. controlling the on/off function of the a/d converter cir- cuitry is implemented using the adonb bit in the acsr register and the value of the pcr bits in the adcr reg- ister. both the adonb bit must cleared to 0 and the value of the pcr bits must have a non-zero value for the a/d converter to be enabled. pcr adonb a/d 0 x off >0 0 on > 0 1 off although the a/d clock source is determined by the sys - tem clock f sys , and by bits adcs2, adcs1 and adcs0, there are some limitations on the maximum a/d clock source speed that can be selected. as the minimum value of permissible a/d clock period, t ad ,is0.5  s, care must be taken for system clock speeds in excess of 4mhz. for system clock speeds in excess of 4mhz, the adcs2, adcs1 and adcs0 bits should not be set to  000 . doing so will give a/d clock periods that are less than the mini - mum a/d clock period which may result in inaccurate a/d conversion values. refer to the following table for exam - ples, where values marked with an asterisk * show where, depending upon the device, special care must be taken, as the values may be less than the specified minimum a/d clock period.  4  6   '     .   /   6 '  . '  / '  6 !  7  * (                ' # (           7  ' # (        f
    
  !    f  ' # (   )   
  f    / a  ' # (   )   
  % 

    
        6 a  ' # (   )   
                ' # (   )   
 6    /    6  a       6    /  a        ' # (   )              !  7     h / h '  . 6 6 6 6 / / / / '  / 6 6 / / 6 6 / / '  6 6 / 6 / 6 / 6 / ' 8 6 ' 8 / ' 8 . ' 8 0 ' 8 1 ' 8 2 ' 8 3 ' 8 4   . 6 6 6 6 / / / /   / 6 6 / / 6 6 / /   6 6 / 6 / 6 / 6 /      7  ' # (               f f  7 6            ' 8 6  7 6 j  7 /            ' 8 6 j ' 8 /  7 6 j  7 .            ' 8 6 j ' 8 .   7 6 j  7 0            ' 8 6 j ' 8 0   7 6 j  7 1            ' 8 6 j ' 8 1  7 6 j  7 2            ' 8 6 j ' 8 2  7 6 j  7 4            ' 8 6 j ' 8 4 a/d converter control register  adcr
ht56r64 rev. 1.60 41 may 21, 2012       ' # (   )         *       8   
      b          h 6 h ' # (   #  f f        
 / a  
     6 a       +                     (            6 ' (  / ' (  6 ' (  / 6 6 / / 6 6 / / ' (  6 6 / 6 / 6 / 6 / a          * # . a          * #  a          * # 0 . a     f
  a          * a          * # 1 a          * # / 3 a     f
   4  !   ' (  8 7 ' (  . ' (  . 6 6 6 6 / / / / a/d converter control register  acsr f sys a/d clock period (t ad ) adcs2, adcs1, adcs0=000 (f sys /2) adcs2, adcs1, adcs0=001 (f sys /8) adcs2, adcs1, adcs0=010 (f sys /32) adcs2, adcs1, adcs0=011 1mhz 2s8 s3 2 s undefined 2mhz 1s4 s1 6 s undefined 4mhz 500ns* 2s8 s undefined 8mhz 250ns* 1s4 s undefined 12mhz 167ns* 667ns* 2.67s undefined a/d clock period examples a/d input pins all of the a/d analog input pins are pin-shared with the i/o pins on port b. bits pcr2~pcr0 in the adcr regis- ter, determine whether the input pins are setup as nor- mal port b input/output pins or whether they are setup as analog inputs. in this way, pins can be changed under program control to change their function from normal i/o operation to analog inputs and vice versa. pull-high re - sistors, which are setup through register programming, apply to the input pins only when they are used as nor - mal i/o pins, if setup as a/d inputs the pull-high resistors will be automatically disconnected. note that it is not necessary to first setup the a/d pin as an input in the pbc port control register to enable the a/d input as when the pcr2~pcr0 bits enable an a/d input, the sta - tus of the port control register will be overridden. the a/d converter has its own power supply pins avdd and avss and a vref reference pin. the analog input val - ues must not be allowed to exceed the value of vref. initialising the a/d converter the internal a/d converter must be initialised in a special way. each time the port b a/d channel selection bits are modified by the program, the a/d converter must be re-initialised. if the a/d converter is not initialised after the channel selection bits are changed, the eocb flag may have an undefined value, which may produce a false end of conversion signal. to initialise the a/d converter after the channel selection bits have changed, then, within a time frame of one to ten instruction cycles, the start bit in the adcr register must first be set high and then im- mediately cleared to zero. this will ensure that the eocb flag is correctly set to a high condition. summary of a/d conversion steps the following summarises the individual steps that should be executed in order to implement an a/d con - version process.  step 1 select the required a/d conversion clock by correctly programming bits adcs2, adcs1 and adcs0 in the acsr register.  step 2 enable the a/d by clearing the adonb in the acsr register to zero.  step 3 select which channel is to be connected to the internal a/d converter by correctly programming the acs2~acs0 bits which are also contained in the adcr register.  step 4 select which pins on port b are to be used as a/d in - puts and configure them as a/d input pins by correctly programming the pcr2~pcr0 bits in the adcr reg - ister. note that this step can be combined with step 2 into a single adcr register programming operation.
ht56r64 rev. 1.60 42 may 21, 2012  step 5 if the interrupts are to be used, the interrupt control reg - isters must be correctly configured to ensure the a/d converter interrupt function is active. the master inter - rupt control bit, emi, in the intc0 interrupt control reg - ister must be set to  1  , the multi-function interrupt enable bit, emfi, in the intc1 register and the a/d converter interrupt bit, eadi, in the intc1 register must also be set to  1  .  step 6 the analog to digital conversion process can now be initialised by setting the start bit in the adcr regis- ter from 0 to 1 and then to 0 again. note that this bit should have been originally set to 0.  step 7 to check when the analog to digital conversion pro - cess is complete, the eocb bit in the adcr register can be polled. the conversion process is complete when this bit goes low. when this occurs the a/d data registers adrl and adrh can be read to obtain the conversion value. as an alternative method if the in - terrupts are enabled and the stack is not full, the pro - gram can wait for an a/d interrupt to occur. note: when checking for the end of the conversion process, if the method of polling the eocb bit in the adcr register is used, the interrupt enable step above can be omitted. the accompanying diagram shows graphically the vari - ous stages involved in an analog to digital conversion process and its associated timing. the setting up and operation of the a/d converter func - tion is fully under the control of the application program as there are no configuration options associated with the a/d converter. after an a/d conversion process has been initiated by the application program, the microcontroller internal hardware will begin to carry out the conversion, during which time the program can continue with other functions. the time taken for the a/d conversion is 16t ad where t ad is equal to the a/d clock period. programming considerations when programming, special attention must be given to the a/d channel selection bits in the adcr register. if these bits are all cleared to zero no external pins will be selected for use as a/d input pins allowing the pins to be used as normal i/o pins. when this happens the power supplied to the internal a/d circuitry will be reduced re- sulting in a reduction of supply current. this ability to re- duce power by turning off the internal a/d function by clearing the a/d channel selection bits may be an impor- tant consideration in battery powered applications. the adonb bit in the acsr register can also be used to power down the a/d function. another important programming consideration is that when the a/d channel selection bits change value, the a/d converter must be re-initialised. this is achieved by pulsing the start bit in the adcr register immediately after the channel selection bits have changed state. the exception to this is where the channel selection bits are all cleared, in which case the a/d converter is not re - quired to be re-initialised. a/d programming example the following two programming examples illustrate how to setup and implement an a/d conversion. in the first example, the method of polling the eocb bit in the adcr register is used to detect when the conversion cycle is complete, whereas in the second example, the a/d interrupt is used to determine when the conversion is complete.  ' ( ' # (   )   
  
 6 6 6 7 " " " 7 / 6 6 7 6 / 6 7   '   !  7   . j   6 '  . j '  6   %          !    f  ' # (  )   
 / a  (  f
       f
    
 . a                  ' # (    *         f    b  f  @  # . b  f  @  # 1 b  f  @  #  b  f  @  # / 3     f  @  # 0 .  ' (  k 1  ' (  ' ( k   ' (  ? l  ' ( m  k 
       f  ' (        
 8    a         f  ' # (  )   
       ' # (  )      ' # (    
  
    ' (   6 6 6 7        f  ' # (  )   
       ' # (  )      / 6 / 7 6 6 / 7        f  ' # (  )   
       ' # (  )      !    f  ' # (  )   
 ' # (    
  
    ' (   6 6 6 7 " " " 7 ' (        8 ' (  8 7  f f  f f     8 .    ' ( ' # (   )   
  
 a/d conversion timing
ht56r64 rev. 1.60 43 may 21, 2012 example: using an eocb polling method to detect the end of conversion clr eadi ; disable adc interrupt mov a,00000001b mov acsr,a ; select f sys /8 as a/d clock and turn on adonb bit mov a,00100000b ; setup adcr register to configure port pb0~pb3 ; as a/d inputs mov adcr,a ; and select an0 to be connected to the a/d converter : : ; as the port b channel bits have changed the ; following start ; signal (0-1-0) must be issued ; instruction cycles : start_conversion: clr start set start ; reset a/d clr start ; start a/d polling_eoc: sz eocb ; poll the adcr register eocb bit to detect end ; of a/d conversion jmp polling_eoc ; continue polling mov a,adrl ; read low byte conversion result value mov adrl_buffer,a ; save result to user defined register mov a,adrh ; read high byte conversion result value mov adrh_buffer,a ; save result to user defined register : jmp start_conversion ; start next a/d conversion example: using the interrupt method to detect the end of conversion clr eadi ; disable adc interrupt mov a,00000001b mov acsr,a ; select f sys /8 as a/d clock and turn on adonb bit mov a,00100000b ; setup adcr register to configure port pb0~pb3 ; as a/d inputs mov adcr,a ; and select an0 to be connected to the a/d : ; as the port b channel bits have changed the ; following start signal(0-1-0) must be issued ; : start_conversion: clr start set start ; reset a/d clr start ; start a/d clr adf ; clear adc interrupt request flag set eadi ; enable adc interrupt set emfi ; enable multi-function interrupt set emi ; enable global interrupt : : : ; adc interrupt service routine adc_: mov acc_stack,a ; save acc to user defined memory mov a,status mov status_stack,a ; save status to user defined memory : : mov a,adrl ; read low byte conversion result value mov adrl_buffer,a ; save result to user defined register mov a,adrh ; read high byte conversion result value mov adrh_buffer,a ; save result to user defined register : : exit__isr: mov a,status_stack mov status,a ; restore status from user defined memory mov a,acc_stack ; restore acc from user defined memory clr adf ; clear adc interrupt flag reti
ht56r64 rev. 1.60 44 may 21, 2012 + + ! d =          > ' # (   )   
       + + + d + + ( d 6 0 d 6 . d 6 / d 6 < 2  $  7 6 / . 0 1 6 5 0 1 6 5 1 1 6 5 2 1 6 5 3 '          &       / < 2  $  7 & ( ( 1 6 5 3 ideal a/d transfer function a/d transfer function as the device contain a 12-bit a/d converter, its full-scale converted digitised value is equal to fffh. since the full-scale analog input value is equal to the vdd voltage, this gives a single bit analog input value of v dd /4096. the diagram show the ideal transfer function between the analog input value and the digitised output value for the a/d converter. note that to reduce the quantisation error, a 0.5 lsb off - set is added to the a/d converter input. except for the digitised zero value, the subsequent digitised values will change at a point 0.5 lsb below where they would change without the offset, and the last full scale digitised value will change at a point 1.5 lsb below the v dd level. serial interface the device contains both spi and i 2 c serial interface functions, which allows two methods of easy communi - cation with external peripheral hardware. as the spi and i 2 c function share the same external pins and internal registers their function must first be chosen by selecting the correct configuration option. spi interface the spi interface is often used to communicate with ex- ternal peripheral devices such as sensors, flash or eeprom memory devices etc. originally developed by motorola, the four line spi interface is a synchronous serial data interface that has a relatively simple commu- nication protocol simplifying the programming require- ments when communicating with external hardware devices.  spi interface operation the spi interface is a full duplex synchronous serial data link. communication between devices con - nected to the spi interface is carried out in a slave/master mode with all data transfer initiations be - ing implemented by the master. multiple slave devices can be connected to the spi serial bus with each de - vice controlled using its slave select line. the spi is a four line interface with pin names sdi, sdo, sck and scs . pins sdi and sdo are the serial data input and serial data output lines, sck is the serial clock line and scs is the slave select line. as the spi interface pins are pin-shared with segment pins and with the i2c function pins, the spi interface must first be en - abled by selecting the correct configuration option. af - ter the spi configuration option has been selected it can then also be selected using the simen bit in the simcon0 register. the spi function in this device offers the following fea - tures:  full duplex synchronous data transfer  both master and slave modes  lsb first or msb first data transmission modes  transmission complete flag  supports uart interface bridge  idle mode supported several other configuration options also exist to setup various spi interface options as follows:  spi pin enabled  rising or falling active clock edge  wcol bit enabled or disabled  csen bit enabled or disabled
ht56r64 rev. 1.60 45 may 21, 2012 ( 4 ( 3 ( 2 ( 1 ( 0 ( . ( / ( 6    (   =   
)    (       
    >   :  (   7  f f     :  $  (     7     :              )   (   (         7            *  ;   *      
  . / 6    ! 8        7     +       ! 8  
      (    $  +      +   b          ! 8 ! 8 ' 8 (  
    7 (   
      (   !     # (
       ! 8              )   ! 8    ! 8   b         b       block diagram the status of the spi interface pins is determined by a number of factors, whether the device is in master or slave mode and upon the condition of certain control bits such as csen and simen. master/salve (simen=0) master (simen=1) slave (=1) csen=1 csen=0 csen=0 scs line=0 (csen=1) scs line=1 (csen=1) scs zl z zi , zi , z s d ozooooz sdi z i, z i, z i, z i, z z sck z l(cpol=1) h(cpol=0) l(cpol=1) h(cpol=0) i, z i, z z z floating, h output high, l output low, i input, o output level, i,z input floating (no pull-high) spi interface pin status  spi registers the simdr register is used to store the data being transmitted and received. there are two control regis - ters associated with the spi interface, simcon0 and simcon2 and one data register known as simdr. the simcon1 register is not used by the spi func - tion. register simcon0 is used to control the en - able/disable function, the power down control and to set the data transmission clock frequency. register simcon2 is used for other control functions such as lsb/msb selection, write collision flag etc. the following gives further explanation of each bit:  simen the simen bit is the overall on/off control for the spi interface. when the simen bit is cleared to zero to disable the spi interface, the sdi, sco, sck and scs lines will be in a floating condition and the spi operating current will be reduced to <0.1 a at 5v. when the bit is high the spi interface is enabled. note that when the simen bit changes from low to high the contents of the spi control reg - isters will be in an unknown condition and should therefore be initialised by the application program.  simidle the simidle bit is used to select if the spi interface continues running when the device is in the idle mode. setting the bit high allows the spi clock to keep running and enables the spi interface to main- tain operation when the device is in the idle mode. clearing the bit to zero disables any spi operations when in the idle mode.
ht56r64 rev. 1.60 46 may 21, 2012  ' & ( /                    
          / a       6 a  
          #  f       / a       6 a  
       
        *            
        %               #    )        *          .         /         6  6    ! 8      b  f  @  # 1      b  f  @  # / 3      b  f  @  # 3 1      b  f   7      b  
  # ! )          6       # .    )  8        8        6 6 6 6 / / / / 6 6 / / 6 6 / /  4    /    6    . 6 / 6 / 6 / 6 /  ; ! 8  ;   /  ;   6     ( $ ! spi control register  simcon0  ' & ( /           4    
 #   
)         f    / a           f         6 a           f   
      
     

  f    / a         

 6 a      

   
      / a       6 a  
     b     f    
 (      
f        / a    7  f
   6 a  $  7  f
   8   
      b          h 6 h  6   $   +  ! 8  $  spi control register  simcon2    6        # .  ;        ;   6  ;   /   *                      ( $ !          ; ! 8    #  .    ! 8     c . a 6 e   / / /  ' & &  0 - $     -   -   f  @            k  d ' $   n   ( $ ! 8 k 6           k  d ' $   n   ( $ ! 8 k / 8    a  spi sim module structure
ht56r64 rev. 1.60 47 may 21, 2012  sim0~sim2 these three bits control the master/slave selection and also setup the spi interface clock speed when in the master mode. the spi clock is a function of the system clock whether it be rc type or crystal type but can also be chosen to be sourced from timer/event counter 0 divided by two. if the slave mode is selected then the clock will be supplied by the external master device. the following gives further explanation of each bit:  trf the trf bit is the transmit/receive complete flag and is cleared by the application program and can be used to generate an interrupt. when the bit is high the data has been transmitted or received. if the bit is low the data is being transmitted or has not yet been received.  wcol the wcol bit is used to detect if a data collision has occurred. if this bit is high it means that data has been attempted to be written to the smdr reg - ister during a data transfer operation. this writing operation will be ignored if data is being transferred. the bit can be cleared by the application program. note that using the scen bit can be disabled or en - abled via configuration option.  csen the csen bit is used as an on/off control for the scs pin. if this bit is low then the scs pin will be dis - abled and placed into a floating condition. if the bit is high the scs pin will be enabled and used as a se - lect pin.  mls the mls is used to select how the data is trans - ferred, either msb or lsb first. setting the bit high will select msb first and low for lsb first. note that the simcon2 register is the same as the simar register used by the i 2 c interface.  spi communication after the spi interface is enabled by setting the simen bit high, then in the master mode, when data is written to the simdr register, transmission/reception will begin simultaneously. when the data transfer is complete, the trf flag will be set automatically. in the slave mode, when the clock signal from the master has been received, any data in the simdr register will be transmitted and any data on the sdi pin will be shifted into the simdr register. the master should output an scs signal before a clock signal is provided and slave data transfers should be enabled/disabled before/after an scs signal is received.  ;    (   (  ( / # ( 3 ( 4 # ( 6 ( 3 # ( / ( 2 # ( . ( 1 # ( 0 ( 0 # ( 1 ( . # ( 2 ( / # ( 3 ( 6 # ( 4 ( 4 # ( 6 ( 3 # ( / ( 2 # ( . ( 1 # ( 0 ( 0 # ( 1 ( . # ( 2 ( 6 # ( 4    ! 8 k  ! 8 k /     % 
              (     ! 8 k  / b   ! 8 k  6     % 
              (   =
f        
  >  ; spi interface timing
ht56r64 rev. 1.60 48 may 21, 2012    ! 8  k /  
   (   
      (    $ k / o        $ @    
 
        o =   + k /  o >  8 @      (    f       (         +     f   +

    o 8 @ ! 8 (            )          )  ' '         f     f
     ! 8      $      c . a 6 e k 6 6 6 b 6 6 / b 6 / 6 b 6 / /     / 6 6     c . a 6 e k / 6 / spi transfer control flowchart
ht56r64 rev. 1.60 49 may 21, 2012 i 2 c interface the i 2 c bus is a bidirectional 2-line communication in - terface originally developed by philips. the possibility of transmitting and receiving data on only 2 lines offers many new application possibilities for microcontroller based applications.  i 2 c interface operation as the i 2 c interface pins are pin-shared with segment pins and with the spi function pins, the i 2 c interface must first be enabled by selecting the correct configu - ration option. there are two lines associated with the i2c bus, the first is known as sda and is the serial data line, the second is known as scl line and is the serial clock line. as many devices may be connected together on the same bus, their outputs are both open drain types. for this reason it is necessary that external pull-high resistors are connected to these outputs. note that no chip select line exists, as each device on the i 2 c bus is identified by a unique address which will be transmit - ted and received on the i 2 c bus. when two devices communicate with each other on the bidirectional i 2 c bus, one is known as the master device and one as the slave device. both master and slave can transmit and receive data, however, it is the master device that has overall control of the bus. for this device, which only operates in slave mode, there are two methods of transferring data on the i 2 c bus, the slave transmit mode and the slave receive mode.  i 2 c registers there are three control registers associated with the i 2 c bus, simcon0, simcon1 and simar and one data register, simdr. the simdr register is used to store the data being transmitted and received on the i 2 c bus. before the microcontroller writes data to the i 2 c bus, the actual data to be transmitted must be placed in the simdr register. after the data is received from the i 2 c bus, the microcontroller can read it from the simdr regis - ter. any transmission of data to the i 2 c bus or recep - tion of data from the i 2 c bus must be made via the simdr register. the simar register is the location where the slave address of the microcontroller is stored. bits 1~7 of the simar register define the microcontroller slave address. bit 0 is not defined. when a master device, which is connected to the i 2 c bus, sends out an ad - dress, which matches the slave address in the simar register, the microcontroller slave device will be se - lected. note that the simar register is the same register as simcon2 which is used by the spi interface. the simcon0 register is used for the i 2 c overall on/off control and to describe if the i 2 c interface re - mains active in the idle mode.  ' &            4 8   
      b          h 6 h  .    )
     )           6  ' 2  ' 1  ' 3  ' 6  ' 0  ' .  ' / slave address register  simar  ' & ( /           .        
         / a       6 a  
      .   #  f f       / a       6 a  
     8   
      b          h 6 h  .        #    )        *          .         /         6  6    ! 8     ( $ ! 8        8        8        8        8        8         .     8        6 6 6 6 / / / / 6 6 / / 6 6 / / 6 / 6 / 6 / 6 /  4    /    6    . i 2 c control register  simcon0
ht56r64 rev. 1.60 50 may 21, 2012 the following gives further explanation of each bit:  simen the simen bit determines if the i 2 c bus is enabled or disabled. if data is to be transferred or received on the i 2 c bus then this bit must be set high.  simidle the simidle bit is used to select if the i 2 c interface continues running when the device is in the idle mode. setting the bit high allows the i 2 c interface to maintain operation when the device is in the idle mode. clearing the bit to zero disables any i 2 c op- erations when in the idle mode. the simcon1 register is used to control and moni - tor the status of the i 2 c bus. the following gives further explanation of each bit:  hcf the hcf flag is the data transfer flag. this flag will be zero when data is being transferred. upon com - pletion of an 8-bit data transfer the flag will go high and an interrupt will be generated.  hass the hass flag is the address match flag. this flag is used to determine if the slave device address is the same as the master transmit address. if the ad - dresses match then this bit will be high, if there is no match then the flag will be low.  hbb the hbb flag is the i 2 c busy flag. this flag will be high when the i 2 c bus is busy which will occur when a start signal is detected. the flag will be reset to zero when the bus is free which will occur when a stop signal is detected.  htx the htx flag is the transmit/receive mode bit. this flag should be set high to set the transmit mode and low for the receive mode.  txak the txak flag is the transmit acknowledge flag. af- ter the receipt of 8-bits of data, this bit will be trans- mitted to the bus on the 9th clock. to continue receiving more data, this bit has to be reset to zero before further data is received.  srw the srw bit is the slave read/write bit. this bit de- termines whether the master device wishes to transmit or receive data from the i 2 c bus. when the transmitted address and slave address match, that is when the haas bit is set high, the device will check the srw bit to determine whether it should be in transmit mode or receive mode. if the srw bit is high, the master is requesting to read data from the bus, so the device should be in transmit mode. when the srw bit is zero, the master will write data to the bus, therefore the device should be in receive mode to read this data.  rxak the rxak flag is the receive acknowledge flag. when the rxak bit has been reset to zero it means that a correct acknowledge signal has been re - ceived at the 9th clock, after 8 bits of data have been transmitted. when in the transmit mode, the transmitter checks the rxak bit to determine if the receiver wishes to receive the next byte. the trans - mitter will therefore continue sending out data until the rxak bit is set to 1 . when this occurs, the transmitter will release the sda line to allow the master to send a stop signal to release the bus.  ' & ( /           4   
)    *  %       f    / a      *  %       6 a   *  %       8   
      b          h 6 h                 # % 
     ,      f    / a    ,               6 a    ,           % 
     
   *  %       f    / a    p    *  %      6 a   *  %         
 #   
)      / a     
     6 a    
)       .          f    / a      6 a           
                f    / a       6 a          (         f    f    / a      f         6 a      f             6 d  :  : ' ;     : ' ; d 7 7 d ' '  d + i 2 c control register  simcon1
ht56r64 rev. 1.60 51 may 21, 2012 i 2 c bus communication communication on the i 2 c bus requires four separate steps, a start signal, a slave device address transmis - sion, a data transmission and finally a stop signal. when a start signal is placed on the i 2 c bus, all de - vices on the bus will receive this signal and be notified of the imminent arrival of data on the bus. the first seven bits of the data will be the slave address with the first bit being the msb. if the address of the microcontroller matches that of the transmitted address, the haas bit in the simcon1 register will be set and an i 2 c interrupt will be generated. after entering the interrupt service routine, the microcontroller slave device must first check the condition of the haas bit to determine whether the interrupt source originates from an address match or from the completion of an 8-bit data transfer. during a data transfer, note that after the 7-bit slave address has been transmitted, the following bit, which is the 8th bit, is the read/write bit whose value will be placed in the srw bit. this bit will be checked by the microcontroller to de - termine whether to go into transmit or receive mode. be - fore any transfer of data to or from the i 2 c bus, the microcontroller must initialise the bus, the following are steps to achieve this: step 1 write the slave address of the microcontroller to the i 2 c bus address register simar. step 2 set the simen bit in the simcon0 register to 1 to en - able the i 2 c bus. step 3 set the esim bit of the interrupt control register to en - able the i 2 c bus interrupt.  start signal the start signal can only be generated by the mas - ter device connected to the i 2 c bus and not by the microcontroller, which is only a slave device. this start signal will be detected by all devices con - nected to the i 2 c bus. when detected, this indicates that the i 2 c bus is busy and therefore the hbb bit will be set. a start condition occurs when a high to low transition on the sda line takes place when the scl line remains high.  slave address the transmission of a start signal by the master will be detected by all devices on the i 2 c bus. to deter- mine which slave device the master wishes to com- municate with, the address of the slave device will be sent out immediately following the start signal. all slave devices, after receiving this 7-bit address data, will compare it with their own 7-bit slave address. if the address sent out by the master matches the internal address of the microcontroller slave device, then an internal i 2 c bus interrupt signal will be generated. the next bit following the address, which is the 8th bit, de - fines the read/write status and will be saved to the srw bit of the simcon1 register. the device will then transmit an acknowledge bit, which is a low level, as the 9th bit. the microcontroller slave device will also set the status flag haas when the addresses match. as an i 2 c bus interrupt can come from two sources, when the program enters the interrupt subroutine, the haas bit should be examined to see whether the in - terrupt source has come from a matching slave ad - dress or from the completion of a data byte transfer. when a slave address is matched, the device must be placed in either the transmit mode and then write data to the simdr register, or in the receive mode where it must implement a dummy read from the simdr regis - ter to release the scl line.   '    
   f                 )              #   
  f          ' *  %      f       )               f          ' *  %      f       )       
   f         
ht56r64 rev. 1.60 52 may 21, 2012  srw bit the srw bit in the simcon1 register defines whether the microcontroller slave device wishes to read data from the i 2 c bus or write data to the i 2 c bus. the microcontroller should examine this bit to deter- mine if it is to be a transmitter or a receiver. if the srw bit is set to 1 then this indicates that the master wishes to read data from the i 2 c bus, therefore the microcontroller slave device must be setup to send data to the i 2 c bus as a transmitter. if the srw bit is 0 then this indicates that the master wishes to send data to the i 2 c bus, therefore the microcontroller slave device must be setup to read data from the i 2 c bus as a receiver.  acknowledge bit after the master has transmitted a calling address, any slave device on the i 2 c bus, whose own internal address matches the calling address, must generate an acknowledge signal. this acknowledge signal will inform the master that a slave device has accepted its calling address. if no acknowledge signal is received by the master then a stop signal must be transmitted by the master to end the communication. when the haas bit is high, the addresses have matched and the microcontroller slave device must check the srw bit to determine if it is to be a transmitter or a receiver. if the srw bit is high, the microcontroller slave device should be setup to be a transmitter so the htx bit in the simcon1 register should be set to 1 if the srw bit is low then the microcontroller slave device should be setup as a receiver and the htx bit in the simcon1 register should be set to 0.  data byte the transmitted data is 8-bits wide and is transmitted after the slave device has acknowledged receipt of its slave address. the order of serial bit transmission is the msb first and the lsb last. after receipt of 8-bits of data, the receiver must transmit an acknowledge sig - nal, level 0 , before it can receive the next data byte. if the transmitter does not receive an acknowledge bit signal from the receiver, then it will release the sda line and the master will send out a stop signal to re- lease control of the i2c bus. the corresponding data will be stored in the simdr register. if setup as a transmitter, the microcontroller slave device must first write the data to be transmitted into the simdr regis- ter. if setup as a receiver, the microcontroller slave de- vice must read the transmitted data from the simdr register.  receive acknowledge bit when the receiver wishes to continue to receive the next data byte, it must generate an acknowledge bit, known as txak, on the 9th clock. the microcontroller slave device, which is setup as a transmitter will check the rxak bit in the simcon1 register to determine if it is to send another data byte, if not then it will release the sda line and await the receipt of a stop signal from the master. (    / 6 /        6 6 /        66 / 6 6 / 6 / 6 / /  k       = /  
 >  ' k    )   '        = 4  
  >   k     
  = /  
 >  k    )     )
       *  %       
  = /  
 > ( k (     =   
  > ' k ' ;  =  : ' ;  
  f       
    b   : ' ;  
  f      
)    /  
 >  k     = /  
 >  $       ( '    ' ; ' ;     $  ( '    )   '         '    ( ' ( '   '    ( ' ( '  i 2 c communication timing diagram  $  ( '       
   (             (          %         
 data timing diagram
ht56r64 rev. 1.60 53 may 21, 2012 peripheral clock output the peripheral clock output allows the device to supply external hardware with a clock signal synchronised to the microcontroller clock. as the peripheral clock output pin, pint, is shared with the lcd segment line seg14, the required pin function is chosen via configuration option. the clock source for the peripheral clock output can originate from either the timer/event counter 0 divided by two or a divided ratio of the internal fsys clock. the clock source is se - lected using the pcken bit in the simcon0 register. the required division ratio of the system clock is se - lected using the pckpsc0 and pscpsc1 bits in the same register. if the system enters the power down mode this will also influence the operation of the periph - eral clock output as shown in the block diagram.      d ' '  k / o d  : k /     o    k /      o @   8  @   8   : ' ; k / o @   8  8       f      (   !   @   (        f       (   !    !    
        (   !   d  :  
        (  (        +       (  $   d  : $    : ' ;  !    !   $   d  : $    : ' ; i 2 c bus isr flow chart         
      )    '              '   !      c . a 6 e k / / 6  !      ! 8     .  7          k o  !     (
         !   ! d   
  f           -      
       $   ! d        d  +      
   %              .  7        -      
       i 2 c bus initialisation flow chart
ht56r64 rev. 1.60 54 may 21, 2012    6        # .  ;        ;   6  ;   /   *                      ( $ !          ; ! 8    #  .    ! 8     c . a 6 e   / / /  ' & &  0 - $     -   -   f  @            k  d ' $   n   ( $ ! 8 k 6           k  d ' $   n   ( $ ! 8 k / 8    a  spi sim module structure  ' & ( /                    
               
        %      ;    *         
        *  !      6  a    *  
     /  a    *                 #    )        *            
        %      6    ! 8     ( $ !           *       f  @  f  @  # 1 f  @  #  
  # ! )          6    .  ;   / 6 6 / /  ;   6 6 / 6 /  4    /    6    .  ; ! 8  ;   /  ;   6 peripheral clock output control  simcon0 buzzer operating in a similar way to the programmable fre - quency divider, the buzzer function provides a means of producing a variable frequency output, suitable for ap - plications such as piezo-buzzer driving or other external circuits that require a precise frequency generator. the bz and bz pins form a complimentary pair, and are pin-shared with i/o pins, pa0 and pa1. a configuration option is used to select from one of three buzzer options. the first option is for both pins pa0 and pa1 to be used as normal i/os, the second option is for both pins to be configured as bz and bz buzzer pins, the third option selects only the pa0 pin to be used as a bz buzzer pin with the pa1 pin retaining its normal i/o pin function. note that the bz pin is the inverse of the bz pin which to - gether generate a differential output which can supply more power to connected interfaces such as buzzers. the buzzer is driven by the internal clock source, f s , which then passes through a divider, the division ratio of which is selected by configuration options to provide a range of buzzer frequencies from f s /2 2 to f s /2 9 . the clock source that generates f s , which in turn controls the buzzer frequency, can originate from three different sources, the rtc oscillator, the 32k_int oscillator or the system oscillator/4, the choice of which is deter - mined by the f s clock source configuration option. note that the buzzer frequency is controlled by configuration options, which select both the source clock for the inter - nal clock f s and the internal division ratio. there are no internal registers associated with the buzzer frequency. if the configuration options have selected both pins pa0 and pa1 to function as a bz and bz complementary pair of buzzer outputs, then for correct buzzer operation it is f         f
    
  
 f  @  # 1 f   0 . ; g  8   f
    
   
 (
)
      . . j . 5 f  7 9 7 9 buzzer function
ht56r64 rev. 1.60 55 may 21, 2012 essential that both pins must be setup as outputs by set - ting bits pac0 and pac1 of the pac port control regis - ter to zero. the pa0 data bit in the pa data register must also be set high to enable the buzzer outputs, if set low, both pins pa0 and pa1 will remain low. in this way the single bit pa0 of the pa register can be used as an on/off control for both the bz and bz buzzer pin outputs. note that the pa1 data bit in the pa register has no con - trol over the bz buzzer pin pa1. pa0/pa1 pin function control pac register pac0 pac register pac1 pa data register pa0 pa data register pa1 output function 001x pa0=bz pa1=bz 000x pa0=0 pa1=0 011x pa0=bz pa1=input line 010x pa0=0 pa1=input line 10xd pa0=input line pa1=d 11xx pa0=input line pa0=input line  x stands for don
t care d stands for data 0 or 1 if configuration options have selected that only the pa0 pin is to function as a bz buzzer pin, then the pa1 pin can be used as a normal i/o pin. for the pa0 pin to func- tion as a bz buzzer pin, pa0 must be setup as an output by setting bit pac0 of the pac port control register to zero. the pa0 data bit in the pa data register must also be set high to enable the buzzer output, if set low pin pa0 will remain low. in this way the pa0 bit can be used as an on/off control for the bz buzzer pin pa0. if the pac0 bit of the pac port control register is set high, then pin pa0 can still be used as an input even though the configuration option has configured it as a bz buzzer output. note that no matter what configuration option is chosen for the buzzer, if the port control register has setup the pin to function as an input, then this will override the con- figuration option selection and force the pin to always behave as an input pin. this arrangement enables the pin to be used as both a buzzer pin and as an input pin, so regardless of the configuration option chosen; the ac- tual function of the pin can be changed dynamically by the application program by programming the appropri- ate port control register bit.          *        ' 6  (    7 9            ' 6 7 9            ' /  ' /  (    buzzer output pin control note: the above drawing shows the situation where both pins pa0 and pa1 are selected by configuration option to be bz and bz buzzer pin outputs. the port control register of both pins must have already been setup as out - put. the data setup on pin pa1 has no effect on the buzzer outputs.
ht56r64 rev. 1.60 56 may 21, 2012 interrupts interrupts are an important part of any microcontroller system. when an external event or an internal function such as a timer/event counter or an a/d converter re - quires microcontroller attention, their corresponding in - terrupt will enforce a temporary suspension of the main program allowing the microcontroller to direct attention to their respective needs. the device contains several external interrupt and internal interrupts functions. the external interrupts are controlled by the action of the ex - ternal int0, int1 and pint pins, while the internal inter - rupts are controlled by the timer/event counter overflows, the time base interrupt, the rtc interrupt, the spi/i 2 c interrupt and the the a/d converter interrupt. interrupt registers overall interrupt control, which means interrupt enabling and request flag setting, is controlled by the intc0, intc1 and mfic registers, which are located in the data memory. by controlling the appropriate enable bits in these registers each individual interrupt can be en - abled or disabled. also when an interrupt occurs, the corresponding request flag will be set by the microcontroller. the global enable flag if cleared to zero will disable all interrupts. interrupt operation a timer/event counter overflow, time base, rtc over- flow, spi/i 2 c data transfer complete, an end of a/d con- version or the external interrupt line being triggered will all generate an interrupt request by setting their corre- sponding request flag, if their appropriate interrupt en- able bit is set. when this happens, the program counter, which stores the address of the next instruction to be executed, will be transferred onto the stack. the program counter will then be loaded with a new ad - dress which will be the value of the corresponding inter - rupt vector. the microcontroller will then fetch its next instruction from this interrupt vector. the instruction at this vector will usually be a jmp statement which will jump to another section of program which is known as the interrupt service routine. here is located the code to control the appropriate interrupt. the interrupt service routine must be terminated with a reti statement, which retrieves the original program counter address from the stack and allows the microcontroller to continue with normal execution at the point where the interrupt occurred. the various interrupt enable bits, together with their as - sociated request flags, are shown in the accompanying diagram with their order of priority. once an interrupt subroutine is serviced, all the other in - terrupts will be blocked, as the emi bit will be cleared au - tomatically. this will prevent any further interrupt nesting from occurring. however, if other interrupt requests oc - cur during this interval, although the interrupt will not be immediately serviced, the request flag will still be re - corded. if an interrupt requires immediate servicing while the program is already in another interrupt service routine, the emi bit should be set after entering the rou - tine, to allow interrupt nesting. if the stack is full, the in - terrupt request will not be acknowledged, even if the related interrupt is enabled, until the stack pointer is decremented. if immediate service is desired, the stack must be prevented from becoming full. interrupt priority interrupts, occurring in the interval between the rising edges of two consecutive t2 pulses, will be serviced on the latter of the two t2 pulses, if the corresponding inter - rupts are enabled. in case of simultaneous requests, the following table shows the priority that is applied. interrupt source priority vector external interrupt 0 1 04h external interrupt 1 2 08h timer/event counter 0 overflow 3 0ch timer/event counter 1 overflow 4 10h spi/i2c interrupt 5 14h multi-function interrupt 6 18h the a/d converter interrupt, real time clock interrupt, time base interrupt and external peripheral interrupt all share the same interrupt vector which is 18h. each of these interrupts have their own own individual interrupt flag but also share the same mff interrupt flag. the mff flag will be cleared by hardware once the multi-function interrupt is serviced, however the individ- ual interrupts that have triggered the multi-function inter - rupt need to be cleared by the application program. external interrupt for an external interrupt to occur, the global interrupt enable bit, emi, and external interrupt enable bits, eei0 and eei1, must first be set. additionally the correct interrupt edge type must be selected using the intedge register to enable the external interrupt function and to choose the trigger edge type. an actual external interrupt will take place when the external interrupt request flag, eif0 or eif1, is set, a situation that will occur when a transition, whose type is chosen by the edge select bit, appears on the int0 or int1 pin. the external interrupt pins are pin-shared with the i/o pins pd4 and pd5 and can only be configured as external interrupt pins if their corresponding external interrupt enable bit in the intc0 register has been set. the pin must also be setup as an input by setting the corresponding pdc.4 and pdc.5 bits in the port control register. when the interrupt is enabled, the stack is not full and the correct transition type appears on the
ht56r64 rev. 1.60 57 may 21, 2012 ' /  (               
                   / a              6 a         
     ! "      
       6       / a       6 a  
     ! "      
       /       / a       6 a  
     
  # ! )          6 
            / a       6 a  
     ! "      
       6    ,      f    / a   
)  6 a 
 
)  ! "      
       /    ,      f    / a   
)  6 a 
 
)  
  # ! )          6 
         ,      f    / a   
)  6 a 
 
)  +                             % 
       h 6 h m       %
            
    
         4  6 ! !  / ! !  6 !   !  + 6!  + / !  6   6 + interrupt control register intc0 ' /  (          
  # ! )          / 
            / a       6 a  
        #  . 
            / a       6 a  
        
 f  
 
            / a       6 a  
     8   
      b          h 6 h 
  # ! )          / 
         ,      f    / a   
)  6 a 
 
)     #  . 
         ,      f    / a   
)  6 a 
 
)     
 f  
 
         ,      f    / a   
)  6 a 
 
)  8   
      b          h 6 h  4  6 !  +  !    !  /   / +   +  + + interrupt control register intc1
ht56r64 rev. 1.60 58 may 21, 2012 & ' (         ' # (   )      
            / a       6 a  
          
    * 
            / a       6 a  
     
  7    
            / a       6 a  
     ! "        
     
            / a       6 a  
     ' # (   )      
         ,      f    / a   
)  6 a 
 
)       
    * 
         ,      f    / a   
)  6 a 
 
)  
  7    
         ,      f    / a   
)  6 a 
 
)  ! "        
     
         ,      f    / a   
)  6 a 
 
)   4  6 !  7  !    ! ' (  ' ( +  +  7 + !    ! + interrupt control register mfic '     
                        "   f     7 + b    +      . +                            f  %    '     
     (
                  !               
 
  d
            
 ! "                ,      +     !  + / ! !  6 
  # ! )          6           ,      +      6 + ! !  / !  6  
  # ! )          /           ,      +      / + !  /     #  .           ,      +        + !    ! "                ,      +     !  + 6    
 f  
           ,      +      + + !  +  !   $  % 
  7              ,      +      7 + ! ' (       
    *           ,      +       + !    ' # (   )                ,      +     ' ( + !  7  !   ! "         
               ,      +      ! + interrupt structure
ht56r64 rev. 1.60 59 may 21, 2012 external interrupt pin, a subroutine call to the external interrupt vector at location 04h or 08h, will take place. when the interrupt is serviced, the external interrupt request flags, eif0 or eif1, will be automatically reset and the emi bit will be automatically cleared to disable other interrupts. note that any pull-high resistor selections on this pin will remain valid even if the pin is used as an external interrupt input. the intedge register is used to select the type of active edge that will trigger the external interrupt. a choice of ei - ther rising and falling edge types can be chosen along with an option to allow both edge types to trigger an exter - nal interrupt. note that the intedge register can also be used to disable the external interrupt function. the external interrupt pins are connected to an internal filter to reduce the possibility of unwanted external inter - rupts due to adverse noise or spikes on the external in - terrupt input signal. as this internal filter circuit will consume a limited amount of power, a configuration op- tion is provided to switch off the filter function, an option which may be beneficial in power sensitive applications, but in which the integrity of the input signal is high. care must be taken when using the filter on/off configuration option as it will be applied not only to both the external interrupt pins but also to the timer/event counter exter- nal input pins. individual external interrupt or timer/event counter pins cannot be selected to have a filter on/off function. external peripheral interrupt the external peripheral interrupt operates in a similar way to the external interrupt and is contained within the multi-function interrupt. for an external peripheral interrupt to occur, the global interrupt enable bit, emi, external peripheral interrupt enable bit, epi, and multi-function interrupt enable bit, emfi, must first be set. an actual external peripheral in - terrupt will take place when the external interrupt re - quest flag, pef, is set, a situation that will occur when a negative transition, appears on the pint pin. the exter - nal peripheral interrupt pin is pin-shared with the seg - ment pin seg15, and is configured as a peripheral interrupt pin via a configuration option. when the inter - rupt is enabled, the stack is not full and a negative tran - sition type appears on the external peripheral interrupt pin, a subroutine call to the multi-function interrupt vec - tor at location18h, will take place. when the external peripheral interrupt is serviced, the emi bit will be cleared to disable other interrupts, however only the mff interrupt request flag will be reset. as the pef flag will not be automatically reset, it has to be cleared by the application program. timer/event counter interrupt for a timer/event counter interrupt to occur, the global interrupt enable bit, emi, and the corresponding timer interrupt enable bit, et0i or et1i, must first be set. an actual timer/event counter interrupt will take place when the timer/event counter request flag, t0f or t1f, is set, a situation that will occur when the timer/event counter overflows. when the interrupt is enabled, the stack is not full and a timer/event counter overflow oc- curs, a subroutine call to the timer interrupt vector at lo- cation 0ch or 10c, will take place. when the interrupt is serviced, the timer interrupt request flag, t0f or t1f, will be automatically reset and the emi bit will be automati- cally cleared to disable other interrupts. a/d interrupt the a/d interrupt is contained within the multi-function interrupt. for an a/d interrupt to be generated, the global interrupt enable bit, emi, a/d interrupt enable bit, eadi, and multi-function interrupt enable bit, emfi, must first be ' /  1 * 4 1          8  6  !           8  6  /         8  6  6   8  /  ! (          8  /  /        8  /  6 8   
      b          h 6 h  6  8  /  6  8  6  /  8  6  6  4  8  /  / 6 6 / / 6 / 6 / 
     

        
    f   
        
               
    6 6 / / 6 / 6 / 
     

        
    f   
        
               
    interrupt active edge register  intedge +
      #  f f  f
    
   
  8  / +
     8  6 +
    ! "        8  < 6 ! "        8  < / & ( 
ht56r64 rev. 1.60 60 may 21, 2012 set. an actual a/d interrupt will take place when the a/d interrupt request flag, adf, is set, a situation that will oc - cur when the a/d conversion process has finished. when the interrupt is enabled, the stack is not full and the a/d conversion process has ended, a subroutine call to the multi-function interrupt vector at location18h, will take place. when the a/d interrupt is serviced, the emi bit will be cleared to disable other interrupts, how - ever only the mff interrupt request flag will be reset. as the adf flag will not be automatically reset, it has to be cleared by the application program. spi/i 2 c interface interrupt for an spi/i 2 c interrupt to occur, the global interrupt en - able bit, emi, and the corresponding interrupt enable bit, esim must be first set. an actual spi/i 2 c interrupt will take place when the spi/i 2 c interface request flag, simf, is set, a situation that will occur when a byte of data has been transmitted or received by the spi/i 2 cin - terface when the interrupt is enabled, the stack is not full and a byte of data has been transmitted or received by the spi/i 2 c interface, a subroutine call to the spi/i 2 c interrupt vector at location 14h, will take place. when the interrupt is serviced, the spi/i 2 c request flag, simf will be automatically reset and the emi bit will be auto - matically cleared to disable other interrupts. multi-function interrupt an additional interrupt known as the multi-function inter- rupt is provided. unlike the other interrupts, this interrupt has no independent source, but rather is formed from four other existing interrupt sources, namely the a/d converter interrupt, time base interrupt, real time clock interrupt and the external peripheral interrupt. for a multi-function interrupt to occur, the global interrupt enable bit, emi, and the multi-function interrupt enable bit, emfi, must first be set. an actual multi-function inter - rupt will take place when the multi-function interrupt re - quest flag, mff, is set. this will occur when either a time base overflow, a real time clock overflow, an a/d con - version completion or an external peripheral interrupt is generated. when the interrupt is enabled and the stack is not full, and either one of the interrupts contained within the multi-function interrupt occurs, a subroutine call to the multi-function interrupt vector at location 018h will take place. when the interrupt is serviced, the multi-function request flag, mff, will be automatically reset and the emi bit will be automatically cleared to disable other inter - rupts. however, it must be noted that the request flags from the original source of the multi-function interrupt, namely the time-base interrupt, real time clock inter - rupt, a/d converter interrupt or external peripheral inter - rupt will not be automatically reset and must be manually reset by the application program. real time clock interrupt the real time clock interrupt is contained within the multi-function interrupt. for a real time clock interrupt to be generated, the global interrupt enable bit, emi, real time clock inter - rupt enable bit, erti, and multi-function interrupt enable bit, emfi, must first be set. an actual real time clock interrupt will take place when the real time clock re - quest flag, rtf, is set, a situation that will occur when the real time clock overflows. when the interrupt is en - abled, the stack is not full and the real time clock over - flows, a subroutine call to the multi-function interrupt vector at location18h, will take place. when the real time clock interrupt is serviced, the emi bit will be cleared to disable other interrupts, however only the mff interrupt request flag will be reset. as the rtf flag will not be automatically reset, it has to be cleared by the application program. similar in operation to the time base interrupt, the pur- pose of the rtc interrupt is also to provide an interrupt signal at fixed time periods. the rtc interrupt clock source originates from the internal clock source f s . this f s input clock first passes through a divider, the division ratio of which is selected by programming the appropri- ate bits in the rtcc register to obtain longer rtc inter- rupt periods whose value ranges from 2 8 /f s ~2 15 /f s . the clock source that generates f s , which in turn controls the rtc interrupt period, can originate from three different sources, the rtc oscillator, 32k_int oscillator or the system oscillator/4, the choice of which is determine by the f s clock source configuration option. note that the rtc interrupt period is controlled by both configuration options and an internal register rtcc. a configuration option selects the source clock for the in - ternal clock f s , and the rtcc register bits rt2, rt1 and rt0 select the division ratio. note that the actual divi - sion ratio can be programmed from 2 8 to 2 15 . f         f
    
  
 f  @  # 1 f   0 . ; g  8  (
)
      .  j . / 2 =            
     > f            . / . # f  j . / 2 # f    .   /   6 rtc interrupt
ht56r64 rev. 1.60 61 may 21, 2012 time base interrupt the time base interrupt is contained within the multi-function interrupt. for a time base interrupt to be generated, the global in - terrupt enable bit, emi,time base interrupt enable bit, etbi, and multi-function interrupt enable bit, emfi, must first be set. an actual time base interrupt will take place when the time base interrupt request flag, tbf, is set, a situation that will occur when the time base over- flows. when the interrupt is enabled, the stack is not full and the time base overflows, a subroutine call to the multi-function interrupt vector at location18h, will take place. when the time base interrupt is serviced, the emi bit will be cleared to disable other interrupts, how- ever only the mff interrupt request flag will be reset. as the tbf flag will not be automatically reset, it has to be cleared by the application program. the purpose of the time base function is to provide an interrupt signal at fixed time periods. the time base in - terrupt clock source originates from the time base inter - rupt clock source originates from the internal clock source f s . this f s input clock first passes through a di - vider, the division ratio of which is selected by configura - tion options to provide longer time base interrupt periods. the time base interrupt time-out period ranges from 2 12 /f s ~2 15 /f s . the clock source that generates f s , which in turn controls the time base interrupt period, can originate from three different sources, the rtc os - cillator, the 32k_int internal oscillator or the system os - cillator/4, the choice of which is determine by the f s clock source configuration option. essentially operating as a programmable timer, when the time base overflows it will set a time base interrupt flag which will in turn generate an interrupt request via the multi-function interrupt vector. programming considerations by disabling the interrupt enable bits, a requested inter- rupt can be prevented from being serviced, however, once an interrupt request flag is set, it will remain in this condition in the intc0, intc1 and mfic registers until the corresponding interrupt is serviced or until the re- quest flag is cleared by the application program. it is recommended that programs do not use the call subroutine instruction within the interrupt subroutine. interrupts often occur in an unpredictable manner or need to be serviced immediately in some applications. if only one stack is left and the interrupt is not well con - trolled, the original control sequence will be damaged once a  call subroutine is executed in the interrupt subroutine. all of these interrupts have the capability of waking up the processor when in the power down mode. only the program counter is pushed onto the stack. if the contents of the status or other registers are altered by the interrupt service program, which may corrupt the desired control sequence, then the contents should be saved in advance. f         f
    
  
 f  @  # 1 f   0 . ; g  8   f
    
   
 (
)
      . / . j . / 2 f  
  7            . / . # f  j . / 2 # f  time base interrupt   ( (          4  6 $ & (  i   $ & (   .   /   6   . 6 6 6 6 / / / /   / 6 6 / / 6 6 / /   6 6 / 6 / 6 / 6 /   
   .  # f   . 5 # f   . / 6 # f   . / / # f   . / . # f   . / 0 # f   . / 1 # f   . / 2 # f               
  $  %  &        (             / a       6 a  
         
       i 
*       / a  
     6 a       $  %  &        (             / a    %  )               6 a       )       8   
      b          h 6 h  real time clock control register  rtcc
ht56r64 rev. 1.60 62 may 21, 2012 reset and initialisation a reset function is a fundamental part of any microcontroller ensuring that the device can be set to some predetermined condition irrespective of outside parameters. the most important reset condition is after power is first applied to the microcontroller. in this case, internal circuitry will ensure that the microcontroller, af - ter a short delay, will be in a well defined state and ready to execute the first program instruction. after this power-on reset, certain important internal registers will be set to defined states before the program com - mences. one of these registers is the program counter, which will be reset to zero forcing the microcontroller to begin program execution from the lowest program memory address. in addition to the power-on reset, situations may arise where it is necessary to forcefully apply a reset condition when the microcontroller is running. one example of this is where after power has been applied and the microcontroller is already running, the res line is force - fully pulled low. in such a case, known as a normal oper - ation reset, some of the microcontroller registers remain unchanged allowing the microcontroller to proceed with normal operation after the reset line is allowed to return high. another type of reset is when the watchdog timer overflows and resets the microcontroller. all types of re- set operations result in different register conditions be- ing setup. another reset exists in the form of a low voltage reset, lvr, where a full reset, similar to the res reset is imple- mented in situations where the power supply voltage falls below a certain threshold. reset functions there are five ways in which a microcontroller reset can occur, through events occurring both internally and ex - ternally:  power-on reset the most fundamental and unavoidable reset is the one that occurs after power is first applied to the microcontroller. as well as ensuring that the program memory begins execution from the first memory ad - dress, a power-on reset also ensures that certain other registers are preset to known conditions. all the i/o port and port control registers will power up in a high condition ensuring that all pins will be first set to inputs. although the microcontroller has an internal rc reset function, if the vdd power supply rise time is not fast enough or does not stabilise quickly at power-on, the internal reset function may be incapable of providing proper reset operation. for this reason it is recom - mended that an external rc network is connected to the res pin, whose additional time delay will ensure that the res pin remains low for an extended period to allow the power supply to stabilise. during this time delay, normal operation of the microcontroller will be inhibited. after the res line reaches a certain voltage value, the reset delay time t rstd is invoked to provide an extra delay time after which the microcontroller will begin normal operation. the abbreviation sst in the figures stands for system start-up timer. for most applications a resistor connected between vdd and the res pin and a capacitor connected be - tween vss and the res pin will provide a suitable ex - ternal reset circuit. any wiring connected to the res pin should be kept as short as possible to minimise any stray noise interference. for applications that operate within an environment where more noise is present the enhanced reset cir- cuit shown is recommended. more information regarding external reset circuits is located in application note ha0075e on the holtek website.  !  & ( (     
     
      6 < 5  & ( (     ( power-on reset timing chart  !  6 < / j /  + / 6 *  j / 6 6 *  & ( ( &   6 < 6 /  + l l & ( ( / 8 1 / 1  l 0 6 6  l note: * it is recommended that this component is added for added esd protection ** it is recommended that this component is added in environments where power line noise is significant external res circuit
ht56r64 rev. 1.60 63 may 21, 2012  res pin reset this type of reset occurs when the microcontroller is already running and the res pin is forcefully pulled low by external hardware such as an external switch. in this case as in the case of other reset, the program counter will reset to zero and program execution initi - ated from this point.  low voltage reset  lvr the microcontroller contains a low voltage reset circuit in order to monitor the supply voltage of the device, which is selected via a configuration option. if the supply voltage of the device drops to within a range of 0.9v~v lvr such as might occur when changing the bat - tery, the lvr will automatically reset the device inter - nally. the lvr includes the following specifications: for a valid lvr signal, a low voltage, i.e., a voltage in the range between 0.9v~v lvr must exist for greater than the value t lvr specified in the a.c. characteristics. if the low voltage state does not exceed 1ms, the lvr will ignore it and will not perform a reset function.  watchdog time-out reset during normal operation the watchdog time-out reset during normal opera - tion is the same as a hardware res pin reset except that the watchdog time-out flag to will be set to 1.  watchdog time-out reset during power down the watchdog time-out reset during power down is a little different from other kinds of reset. most of the conditions remain unchanged except that the pro - gram counter and the stack pointer will be cleared to 0 and the to flag will be set to 1 . refer to the a.c. characteristics for t sst details. reset initial conditions the different types of reset described affect the reset flags in different ways. these flags, known as pdf and to are located in the status register and are controlled by various microcontroller operations, such as the power down function or watchdog timer. the reset flags are shown in the table: to pdf reset conditions 0 0 res reset during power-on u u res or lvr reset during normal operation 1 u wdt time-out reset during normal operation 1 1 wdt time-out reset during power down note: u stands for unchanged the following table indicates the way in which the vari- ous components of the microcontroller are affected after a power-on reset occurs. item condition after reset program counter reset to zero interrupts all interrupts will be disabled wdt clear after reset, wdt begins counting timer/event counter timer counter will be turned off prescaler the timer counter prescaler will be cleared input/output ports i/o ports will be setup as inputs stack pointer stack pointer will point to the top of the stack  (   
         
     
          ( wdt time-out reset during normal operation timing chart  (   
         
         wdt time-out reset during power down timing chart $ &      
     
          ( low voltage reset timing chart  !      
     
      6 < 5  & ( ( 6 < 1  & ( (     ( res reset timing chart
ht56r64 rev. 1.60 64 may 21, 2012 the different kinds of resets all affect the internal registers of the microcontroller in different ways. to ensure reliable continuation of normal program execution after a reset occurs, it is important to know what condition the microcontroller is in after a particular reset occurs. the following table describes how each type of reset affects each of the microcontroller internal registers. note that where more than one package type exists the table will reflect the situation for the larger package type. register reset (power-on) res reset (normal operation) wdt time-out (normal operation) wdt time-out (halt) mp0 xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu mp1 xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu bp   0   0   0   u acc xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu pcl 0000 0000 0000 0000 0000 0000 0000 0000 tblp xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu tblh xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu rtcc  00 0111  00 0111  00 0111  uu uuuu status  00 xxxx  uu uuuu  1u uuuu  11 uuuu intc0 0000 0000 0000 0000 0000 0000 uuuu uuuu tmr0 xxxx xxxx xxxx xxxx xxxx xxxx uuuu uuuu tmr0c 00 0 1000 00  0 1000 00  0 1000 uu  u uuuu tmr1h xxxx xxxx xxxx xxxx xxxx xxxx uuuu uuuu tmr1l xxxx xxxx xxxx xxxx xxxx xxxx uuuu uuuu tmr1c 0000 1   0000 1   0000 1   uuuu u   pa 1111 1111 1111 1111 1111 1111 uuuu uuuu pac 1111 1111 1111 1111 1111 1111 uuuu uuuu pb 1111 1111 1111 1111 1111 1111 uuuu uuuu pbc 1111 1111 1111 1111 1111 1111 uuuu uuuu pd 1111 1111 1111 1111 1111 1111 uuuu uuuu pdc 1111 1111 1111 1111 1111 1111 uuuu uuuu pwm0l 0000   0 0000   0 0000   0 uuuu   u pwm0h 0000 0000 0000 0000 0000 0000 uuuu uuuu pwm1l 0000   0 0000   0 0000   0 uuuu   u pwm1h 0000 0000 0000 0000 0000 0000 uuuu uuuu intc1  000 00  000 00  000 00  uuu uu tbhp xxxx xxxx xxxx xxxx xxxx xxxx uuuu uuuu pwm2l 0000   0 0000   0 0000   0 uuuu   u pwm2h 0000 0000 0000 0000 0000 0000 uuuu uuuu pwm3l 0000   0 0000   0 0000   0 uuuu   u pwm3h 0000 0000 0000 0000 0000 0000 uuuu uuuu adrl xxxx  xxxx  xxxx  uuuu  adrh xxxx xxxx xxxx xxxx xxxx xxxx uuuu uuuu adcr 0100 0000 0100 0000 0100 0000 uuuu uuuu acsr 10   000 10   000 10   000 uu   uuu
ht56r64 rev. 1.60 65 may 21, 2012 register reset (power-on) res reset (normal operation) wdt time-out (normal operation) wdt time-out (halt) clkmod 000 0011 000  0011 000  0011 uuuu  uuu pawu 0000 0000 0000 0000 0000 0000 uuuu uuuu papu 0000 0000 0000 0000 0000 0000 uuuu uuuu pbpu 0000 0000 0000 0000 0000 0000 uuuu uuuu pdpu 0000 0000 0000 0000 0000 0000 uuuu uuuu intedge  0000  0000  0000  uuuu lcdctrl 0000 0000 0000 0000 0000 0000 uuuu uuuu lcdout1   00   00   00   uu lcdout2 0000 0000 0000 0000 0000 0000 uuuu uuuu misc 0000 1010 0000 1010 0000 1010 uuuu uuuu mfic 0000 0000 0000 0000 0000 0000 uuuu uuuu simcon0 1110 0000 1110 0000 1110 0000 uuuu uuuu simcon1 1000 00  1 1000 00  1 1000 00  1 uuuu uu  u simdr xxxx xxxx xxxx xxxx xxxx xxxx uuuu uuuu simar/simcon2 0000 0000 0000 0000 0000 0000 uuuu uuuu note: u stands for unchanged x stands for unknown  stands for unimplemented oscillator various oscillator options offer the user a wide range of functions according to their various application require- ments. five types of system clocks can be selected while various clock source options for the watchdog timer are provided for maximum flexibility. all oscillator options are selected through the configuration options. system clock configurations there are five methods of generating the system clock, two high oscillators, two low oscillators and an externally supplied clock. the two high oscillators are the external crystal/ceramic oscillator and the external rc network. the two low oscillators are the fully integrated 32k_int oscillator and the external rtc oscillator. selecting whether the low or high oscillator is used as the system oscillator is implemented using the hlclk bit in the clkmod register. the source clock for the high and low oscillators is chosen via configuration options. the fre - quency of the slow oscillator is also determined using the slowc0~slowc2 bits in the clkmod register. system crystal/ceramic oscillator after selecting the correct oscillator configuration op - tion, for most crystal oscillator configurations, the simple connection of a crystal across osc1 and osc2 will cre - ate the necessary phase shift and feedback for oscilla - tion, without requiring external capacitors. however, for some crystal types and frequencies, to ensure oscilla- tion, it may be necessary to add two small value capaci- tors, c1 and c2. using a ceramic resonator will usually require two small value capacitors, c1 and c2, to be connected as shown for oscillation to occur. the values of c1 and c2 should be selected in consultation with the crystal or resonator manufacturer
s specification. in most applications, resistor r p1 is not required, however for those applications where the lvr function is not used, r p1 may be necessary to ensure the oscillator stops running when vdd falls below its operating range. the internal oscillator circuit contains a filter circuit to re - duce the possibility of erratic operation due to noise on the oscillator pins. more information regarding the oscillator is located in application note ha0075e on the holtek website.   .   / . /   / crystal/ceramic oscillator
ht56r64 rev. 1.60 66 may 21, 2012 crystal oscillator c1 and c2 values crystal/resonator frequency c1 c2 12mhz crystal  8mhz crystal  4mhz crystal  1mhz crystal  455khz resonator (see note 2) 10pf 10pf note: 1. c1 and c2 values are for guidance only. 2. xtal mode configuration option: 455khz. crystal recommended capacitor values external system rc oscillator after selecting the correct configuration option, using the external system rc oscillator requires that a resis - tor, with a value between 47k and 1.5m ,iscon - nected between osc1 and vdd, and a 470pf capacitor is connected to ground. although this is a cost effective oscillator configuration, the oscillation frequency can vary with vdd, temperature and process variations and is therefore not suitable for applications where timing is critical or where accurate oscillator frequencies are re - quired. for the value of the external resistor r osc refer to the appendix section for typical rc oscillator vs. temperature and vdd characteristics graphics. note that an internal capacitor together with the external resistor, r osc , are the components which determine the frequency of the oscillator. the external capacitor shown on the diagram does not influence the frequency of oscillation. this external capacitor should be added to improve oscillator stability if the open-drain osc2 out - put is utilised in the application circuit. the internal oscil - lator circuit contains a filter circuit to reduce the possibility of erratic operation due to noise on the oscil - lator pins. internal 32k_int oscillator when microcontrollers enter a power down condition, their internal clocks are normally switched off to stop microcontroller activity and to conserve power. how - ever, in many microcontroller applications it may be nec - essary to keep some internal functions operational, such as timers, even when the microcontroller is in the power-down mode. to do this, the device has a 32k_int oscillator, which is a fully integrated free run - ning rc oscillator with a typical period of 31.2  sat5v, requiring no external components. it is selected via con - figuration option. when the device enters the power down mode, the system clock will stop running, how - ever the 32k_int oscillator will continue to run if se - lected to keep various internal functions operational. external rtc oscillator with a function similar to the internal 32k-int 32khz os - cillator, that is to keep some device functions opera - tional during power down, this device also has an external rtc oscillator. this oscillator also remains ac - tive at all times, even when the microcontroller is in the power-down mode. this clock source has a fixed fre - quency of 32768hz and requires a 32768hz crystal to be connected between pins osc3 and osc4. the external resistor and capacitor components con- nected to the 32768hz crystal are not necessary to pro- vide oscillation. for applications where precise rtc frequencies are essential, these components may be required to provide frequency compensation due to dif- ferent crystal manufacturing tolerances. a configuration option selects whether the external rtc oscillator or the internal 32k_int oscillator is selected. se - lecting the external rtc oscillator for use as a system os - cillator is implmented using bits in the clkmod register. during power-up there is a time delay associated with the rtc oscillator waiting for it to start-up. to minimise this time delay, bit 4 of the rtcc register, known as the qosc bit, is provided to have a quick start-up function. during a power-up condition, this bit will be cleared to zero which will initiate the rtc oscillator quick start-up function. however, as there is additional power con - sumption associated with this quick start-up function, to reduce power consumption after start-up takes place, it is recommended that the application program should set the qosc bit high for about 2 seconds after power-on. it should be noted that, no matter what condi - tion the qosc bit is set to, the rtc oscillator will always function normally, only there is more power consump - tion associated with the quick start-up function.   /   . f  @  # 1  8        (  
1 4 6 + & ( (    rc oscillator   1   0 1 0   . 0 . 4 3  d q f   external rtc oscillator       0 . ; g  8  f  0 . ; internal 32k_int oscillator
ht56r64 rev. 1.60 67 may 21, 2012 32768hz oscillator c1 and c2 values crystal frequency c3 c4 32768hz 8pf 10pf note: 1. c3 and c4 values are for guidance only. 2. r p2 =5m~10m is recommended. 32768 hz crystal recommended capacitor values external oscillator the system clock can also be supplied by an externally supplied clock giving users a method of synchronising their external hardware to the microcontroller operation. this is selected using a configuration option and supply - ing the clock on pin osc1. pin osc2 should be left floating if the external oscillator is used. the internal os - cillator circuit contains a filter circuit to reduce the possi - bility of erratic operation due to noise on the oscillator pin, however as the filter circuit consumes a certain amount of power, a configuration option exists to turn this filter off. not using the internal filter should be con - sidered in power sensitive applications and where the externally supplied clock is of a high integrity and sup - plied by a low impedance source. dual clock mode the device has a dural clock mode for system clock op - eration, one is known as the high oscillator and the other as the low oscillator. the high system clock source f m is selected using a configuration option and can be either an external crystal or external rc oscillator. the low oscillator clock source, also known as the sub-clock, f sub , is selected also by configuration option and can be either the external rtc oscillator or the in - ternal 32k_int oscillator. the actual frequency of the slow system clock, f slow ,is also determined using the slowc0~slowc2 bits in the clkmod register. the lcd clock source is provided by f lcd which is f sub divided by 8, giving a frequency of 4khz. the f s clock is an internal clock source for the buzzer, the rtc oscillator interrupt, the time base interrupt and the watchdg timer. the source clock for f s is selected from one of the oscillators, f sub or f sys /4, using a config - uration option. the dual clock mode can operate in four states as fol - lows:  normal mode: f m on, f slow on, f sys =f m , cpu on, f s on, f lcd on/off (using the lcden bit), f wdt on/off (us - ing a configuration option or wdt control register).  slow mode0: f m off, f slow =32k_int oscillator or rtc oscillator, f sys =f slow , cpu on, f s on, f lcd on/off (using the lcden bit), f wdt on/off (using a configura - tion option or wdt control register).  slow mode1: f m on, f slow =f m /2~f m /64, f sys =f slow , cpu on, f s on, f lcd on/off (using the lcden bit), f wdt on/off (using a configuration option or wdt control register).  idle mode: f m ,f slow ,f sys off, cpu off; f sub on, f s on/off (by selecting f sub or f sys /4), f lcd on/off (using the lcden bit), f wdt on/off (using a configuration op - tion or wdt control register).  sleep mode: f m ,f slow ,f sys ,f s ,f lcd off, cpu off; f sub , f wdt on/off (using a configuration option or wdt con - trol register). (  5 & *         f  @        / a  f  6 a  f  $           / a       6 a  
     d
    
             f    / a  
     6 a    
     $  %   
             f    / a  
     6 a    
     8   
      b          h 6 h f  $        
  6  ( $ ! 8 d $ $ ; d  $    4  $   6  $   /  $   . f  $   f  $ f  $ f  # 3 1 f  # 0 . f  # / 3 f  #  f  # 1 f  # .  $    . 6 6 6 6 / / / /  $    / 6 6 / / 6 6 / /  $    6 6 / 6 / 6 / 6 / clock control register  clkmod
ht56r64 rev. 1.60 68 may 21, 2012 /    " $ &  0   %  *    d ' $   n  h  ( $ ! 8 h  k  6 d ' $   n  h  ( $ ! 8 h  k  / %  *     %  *    d ' $   n  h  ( $ ! 8 h  k  / d ' $   n  h  ( $ ! 8 h  k  6 %  *        h d $ $ ; h       h d $ $ ; h 6 *  !  # 0  #   # 3 *   # " 7 $   0   " 7 $    # 0     # 8 9 1      :   (   :  ( ,  5 7   # 8 f    b f       f  0 . ;   b f  @  k f   $   ! &  0  f    f f b f       f  0 . ;   l b f  @  k  f f ' 0 $  &  0  f    f f b f       f  0 . ;   r b f  @  k  f f  $  ; &  0  f    #  f f b f       f  0 . ;   b f  @   k  f  # .  j  f  # 3 1    f       f  0 . ; dual clock mode operation   : f  $   d $ $ ;  7
 f  @  f    : f   f  $    %   *       $   6   0 . 4 3  d q f  0 . ;  f
    
  
  $   /  $   . f  # . b  < < <  f  # 3 1 b  f  $   :   : f  f  @  # 1 f   7 f  @  # 1 f   7 
  /  /  f     *        f
    
   
 f   7   f $ ( k  f   7 #  $ (   
      b 
  7    
      b 7  q q   b   (        0 . ; g  8  $  %   
        0   1 ! "       ! "      :  ' $   : f  ! "      # :  ' $ #   f
    
   
 d
    
        /   .   /   . +
    ! "         *  +
      f f  f
    
   
 ! "        *   / dual clock mode structure
ht56r64 rev. 1.60 69 may 21, 2012 power down mode and wake-up power down mode all of the holtek microcontrollers have the ability to enter a power down mode. when the device enters this mode, the normal operating current, will be reduced to an extremely low standby current level. this occurs be - cause when the device enters the power down mode, the system oscillator is stopped which reduces the power consumption to extremely low levels, however, as the device maintains its present internal condition, it can be woken up at a later stage and continue running, without requiring a full reset. this feature is extremely important in application areas where the mcu must have its power supply constantly maintained to keep the device in a known condition but where the power supply capacity is limited such as in battery applications. entering the power down mode there is only one way for the device to enter the power down mode and that is to execute the  halt instruc - tion in the application program. when this instruction is executed, the following will occur:  the system oscillator will stop running and the appli - cation program will stop at the halt instruction.  the data memory contents and registers will maintain their present condition.  the wdt will be cleared and resume counting if the wdt clock source is selected to come from the wdt oscillator. the wdt will stop if its clock source origi- nates from the system clock.  the i/o ports will maintain their present condition.  in the status register, the power down flag, pdf, will be set and the watchdog time-out flag, to, will be cleared. standby current considerations as the main reason for entering the power down mode is to keep the current consumption of the mcu to as low a value as possible, perhaps only in the order of several micro-amps, there are other considerations which must also be taken into account by the circuit designer if the power consumption is to be minimized. special atten - tion must be made to the i/o pins on the device. all high-impedance input pins must be connected to either a fixed high or low level as any floating input pins could create internal oscillations and result in increased cur - rent consumption. this also applies to devices which have different package types, as there may be undonbed pins, which must either be setup as outputs or if setup as inputs must have pull-high resistors con - nected. care must also be taken with the loads, which are connected to i/o pins, which are setup as outputs. these should be placed in a condition in which minimum current is drawn or connected only to external circuits that do not draw current, such as other cmos inputs. also note that additional standby current will also be re - quired if the configuration options have enabled the watchdog timer internal oscillator. wake-up after the system enters the power down mode, it can be woken up from one of various sources listed as follows:  an external reset  an external falling edge on port a  a system interrupt  a wdt overflow if the system is woken up by an external reset, the de - vice will experience a full system reset, however, if the device is woken up by a wdt overflow, a watchdog timer reset will be initiated. although both of these wake-up methods will initiate a reset operation, the ac - tual source of the wake-up can be determined by exam - ining the to and pdf flags. the pdf flag is cleared by a system power-up or executing the clear watchdog timer instructions and is set when executing the  halt instruction. the to flag is set if a wdt time-out occurs, and causes a wake-up that only resets the program counter and stack pointer, the other flags remain in their original status. each pin on port a can be setup via an individual config- uration option to permit a negative transition on the pin to wake-up the system. when a port a pin wake-up oc- curs, the program will resume execution at the instruc- tion following the  halt instruction. if the system is woken up by an interrupt, then two possi- ble situations may occur. the first is where the related interrupt is disabled or the interrupt is enabled but the stack is full, in which case the program will resume exe - cution at the instruction following the  halt instruction. in this situation, the interrupt which woke-up the device will not be immediately serviced, but will rather be ser - viced later when the related interrupt is finally enabled or when a stack level becomes free. the other situation is where the related interrupt is enabled and the stack is not full, in which case the regular interrupt response takes place. if an interrupt request flag is set to 1 be - fore entering the power down mode, the wake-up func - tion of the related interrupt will be disabled. no matter what the source of the wake-up event is, once a wake-up situation occurs, a time period equal to 1024 system clock periods will be required before normal sys - tem operation resumes. however, if the wake-up has originated due to an interrupt, the actual interrupt sub - routine execution will be delayed by an additional one or more cycles. if the wake-up results in the execution of the next instruction following the  halt instruction, this will be executed immediately after the 1024 system clock period delay has ended.
ht56r64 rev. 1.60 70 may 21, 2012 low voltage detector  lvd this low voltage detect internal function provides a means for the user to monitor when the power supply voltage falls below a certain fixed level as specified in the dc characteristics. bits 3 and 5 of the rtcc register are used to control the overall function of the lvd. bit 3 is the enable/disable control bit and is known as lvdc, when set low the overall function of the lvd will be dis - abled. bit 5 is the lvd detector output bit and is known as lvdo. under normal operation, and when the power supply voltage is above the specified vlvd value in the dc characteristic section, the lvdo bit will remain at a zero value. if the power supply voltage should fall below this vlvd value then the lvdo bit will change to a high value indicating a low voltage condition. note that the lvdo bit is a read-only bit. by polling the lvdo bit in the rtcc register, the application program can therefore determine the presence of a low voltage condition. after power-on, or after a reset, the lvd will be switched off by clearing the lvdc bit in the rtcc register to zero. note that if the lvd is enabled there will be some power consumption associated with its internal circuitry, how - ever, by clearing the lvdc bit to zero the power can be minimised. it is important not to confuse the lvd with the lvr function. in the lvr function an automatic reset will be generated by the microcontroller, whereas in the lvd function only the lvdo bit will be affected with no influence on other microcontroller functions. there are a range of voltage values, selected using a configuration option, which can be chosen to activate the lvd. watchdog timer the watchdog timer is provided to prevent program malfunctions or sequences from jumping to unknown lo - cations, due to certain uncontrollable external events such as electrical noise. it operates by providing a de - vice reset when the watchdog timer counter overflows. the watchdog timer clock source is provided by the in - ternal clock, f s , which is in turn supplied by one of two sources selected by configuration option: f sub or f sys /4. note that if the watchdog timer configuration option has been disabled, then any instruction relating to its op - eration will result in no operation. most of the watchdog timer options, such as en - able/disable, watchdog timer clock source and clear instruction type are selected using configuration op - tions. in addition to a configuration option to enable the watchdog timer, there are four bits, wdten3~ wdten0, in the misc register to offer an additional en - able control of the watchdog timer. these bits must be set to a specific value of 1010 to disable the watchdog timer. any other values for these bits will keep the watchdog timer enabled. after power on these bits will have the disabled value of 1010. one of the wdt clock sources is the internal f sub , which can be sourced from either the 32k_int internal oscilla - tor or the rtc oscillator. the 32k_int internal oscillator has an approximate period of 31.2  s at a supply voltage of 5v. however, it should be noted that this specified in- ternal clock period can vary with vdd, temperature and process variations. the rtc oscillator is supplied by an external 32768hz crystal. the other watchdog timer f         f
    
   
       (       f
    
   
 $    (  /  +    $    (  .  +    /     .       
  f  @  # 1 / 3  
        (   
     = . / 0 # f  b  . / 1 # f  b  . / 2 # f      . / 3 # f  >  f
   
 $   f  f  0 . ; f   watchdog timer & '  (          4  (  ! 8 6  6  (  ! 8 /  ' 6 j  ' 0     (  
           
        %             
   !            ( ! 6  (  ! 8 0 /  (  ! 8 .  (  ! 8 0  ( ! /  ( ! .  ( ! 0  (  ! 8 . 6  (  ! 8 / /  (  ! 8 6 6 
                    )      watchdog timer software control  misc
ht56r64 rev. 1.60 71 may 21, 2012 clock source option is the f sys /4 clock. whether the watchdog timer clock source is its own internal 32k_int, the rtc oscillator or f sys /4, it is divided by 2 13 ~2 16 , using configuration option to obtain the re - quired watchdog timer time-out period. the max time out period is when the 2 16 option is selected. this time-out period may vary with temperature, vdd and process variations. as the clear instruction only resets the last stage of the divider chain, for this reason the ac - tual division ratio and corresponding watchdog timer time-out can vary by a factor of two. the exact division ratio depends upon the residual value in the watchdog timer counter before the clear instruction is executed. if the f sys /4 clock is used as the watchdog timer clock source, it should be noted that when the system enters the power down mode, then the instruction clock is stopped and the watchdog timer will lose its protecting purposes. for systems that operate in noisy environ - ments, using the 32k_int rc oscillator is strongly rec - ommended. under normal program operation, a watchdog timer time-out will initialise a device reset and set the status bit to. however, if the system is in the power down mode, when a watchdog timer time-out occurs, the to bit in the status register will be set and only the program counter and stack pointer will be reset. three methods can be adopted to clear the contents of the watchdog timer. the first is an external hardware reset, which means a low level on the res pin, the second is using the watchdog software instructions and the third is via a halt instruction. there are two methods of using software instructions to clear the watchdog timer, one of which must be chosen by configuration option. the first option is to use the sin - gle  clr wdt  instruction while the second is to use the two commands  clr wdt1  and  clr wdt2  . for the first option, a simple execution of  clr wdt  will clear the wdt while for the second option, both  clr wdt1  and  clr wdt2  must both be executed to successfully clear the watchdog timer. note that for this second op - tion, if  clr wdt1  is used to clear the watchdog timer, successive executions of this instruction will have no ef - fect, only the execution of a  clr wdt2  instruction will clear the watchdog timer. similarly after the  clr wdt2 instruction has been executed, only a successive  clr wdt1  instruction can clear the watchdog timer. configuration options configuration options refer to certain options within the mcu that are programmed into the device during the program- ming process. during the development process, these options are selected using the ht-ide software development tools. as these options are programmed into the device using the hardware programming tools, once they are selected they cannot be changed later as the application software has no control over the configuration options. all options must be defined for proper system function, the details of which are shown in the table. no. options oscillator options 1 oscillator type selection: external crystal oscillator external rc oscillator externally supplied clock - internal filter on externally supplied clock - internal filter off 2f sub clock selection: rtc or 32k_int 3f s clock selection: f sub or f sys /4 4 xtal mode selection: 455khz or 1m~12mhz 5 32768 xtal: enable or disable pfd options 6 pa3: normal i/o or pfd output 7 pfd clock selection: timer/event counter 0 or timer/event counter 1 buzzer options 8 pa0/pa1: normal i/o or bz/bz or pa0=bz and pa1 as normal i/o 9 buzzer frequency: f s /2 2 ,f s /2 3 ,f s /2 4 ,f s /2 5 ,f s /2 6 ,f s /2 7 ,f s /2 8 ,f s /2 9
ht56r64 rev. 1.60 72 may 21, 2012 no. options time base options 10 time base time-out period: 2 12 /f s ,2 13 /f s ,2 14 /f s ,2 15 /f s , lcd options 11 lcd type: r or c watchdog options 12 watchdog timer function: enable or disable 13 clrwdt instructions: 1 or 2 instructions 14 wdt time-out period: 2 12 /f s ~2 13 /f s ,2 13 /f s ~2 14 /f s ,2 14 /f s ~2 15 /f s ,2 15 /f s ~2 16 /f s lvd/lvr options 15 lvd function: enable or disable 16 lvr function: enable or disable 17 lvr/lvd voltage: 2.1v/2.2v or 3.15v/3.3v or 4.2v/4.4v spi 18 spi pin enable/disable 19 spi_cpol : clock polarity is rising or falling edge 20 spi_wcol : enable/disable 21 spi_csen : enable/disable, used to enable/disable (1/0) software csen function i 2 c 22 i 2 c pin enable (if spi & i2c both function pin enabled. spi pin has higher priority) pclk function 23 peripheral clock output - pclk or segment pin - seg14 pintb function 24 external peripheral interrupt or segment function timer/event counter and external interrupt pins filter function 25 interrupt and timer/event counter input pins internal filter on/off control  applies to all pins lock options 26 lock all 27 partial lock
application circuits ht56r64 rev. 1.60 73 may 21, 2012         ' 6 # 7 9  ' / # 7 9  ' .  ' 0 #  + (  ' 1 #    .  ' 2 #    0  ' 3 b   ' 4   /   .  
 
   6 j   .   0 #  ! - 0 .  ! - 6 j  ! - 0 / $ (     & $ ( / & ( ( j  7 6 # ' 8 6  7 4 # ' 8 4  ( 6 #    6  ( 0 #    0 j  ( 3 #    6  ( 4 #    /  ( 1 #  8  6  ( 2 #  8  /  ( (    -     /   .   / / .  (  %        $ $ "    . 1 *  s    s 4 2 6 *       /   . & ( ( 1 4 6 + f  @  # 1 ,  <  =  > (  %   " $    $ $ "     ( , )  (  $  "   #    0   1   0   1  
 
 / . & / & $ ( . 6 < /  + 6 < /  + 6 < /  + (  %   " $      # "     %        $ $ "    +       
        
 / b  .      /      
         
 &  ' :   0   1   . 0 1  !  & ( ( &   6 < /  + & ( (      (    -   6 < / j /  + / 6 *  j / 6 6 *  0 6 6  6 < 6 /  + / 8 1 / 1 
ht56r64 rev. 1.60 74 may 21, 2012 instruction set introduction central to the successful operation of any microcontroller is its instruction set, which is a set of pro - gram instruction codes that directs the microcontroller to perform certain operations. in the case of holtek microcontrollers, a comprehensive and flexible set of over 60 instructions is provided to enable programmers to implement their application with the minimum of pro - gramming overheads. for easier understanding of the various instruction codes, they have been subdivided into several func - tional groupings. instruction timing most instructions are implemented within one instruc - tion cycle. the exceptions to this are branch, call, or ta - ble read instructions where two instruction cycles are required. one instruction cycle is equal to 4 system clock cycles, therefore in the case of an 8mhz system oscillator, most instructions would be implemented within 0.5  s and branch or call instructions would be im - plemented within 1  s. although instructions which re - quire one more cycle to implement are generally limited to the jmp, call, ret, reti and table read instruc- tions, it is important to realize that any other instructions which involve manipulation of the program counter low register or pcl will also take one more cycle to imple- ment. as instructions which change the contents of the pcl will imply a direct jump to that new address, one more cycle will be required. examples of such instruc- tions would be  clr pcl or  mov pcl, a . for the case of skip instructions, it must be noted that if the re- sult of the comparison involves a skip operation then this will also take one more cycle, if no skip is involved then only one cycle is required. moving and transferring data the transfer of data within the microcontroller program is one of the most frequently used operations. making use of three kinds of mov instructions, data can be transferred from registers to the accumulator and vice-versa as well as being able to move specific imme - diate data directly into the accumulator. one of the most important data transfer applications is to receive data from the input ports and transfer data to the output ports. arithmetic operations the ability to perform certain arithmetic operations and data manipulation is a necessary feature of most microcontroller applications. within the holtek microcontroller instruction set are a range of add and subtract instruction mnemonics to enable the necessary arithmetic to be carried out. care must be taken to en - sure correct handling of carry and borrow data when re - sults exceed 255 for addition and less than 0 for sub - traction. the increment and decrement instructions inc, inca, dec and deca provide a simple means of increasing or decreasing by a value of one of the values in the destination specified. logical and rotate operations the standard logical operations such as and, or, xor and cpl all have their own instruction within the holtek microcontroller instruction set. as with the case of most instructions involving data manipulation, data must pass through the accumulator which may involve additional programming steps. in all logical data operations, the zero flag may be set if the result of the operation is zero. another form of logical data manipulation comes from the rotate instructions such as rr, rl, rrc and rlc which provide a simple means of rotating one bit right or left. different rotate instructions exist depending on pro - gram requirements. rotate instructions are useful for serial port programming applications where data can be rotated from an internal register into the carry bit from where it can be examined and the necessary serial bit set high or low. another application where rotate data operations are used is to implement multiplication and division calculations. branches and control transfer program branching takes the form of either jumps to specified locations using the jmp instruction or to a sub- routine using the call instruction. they differ in the sense that in the case of a subroutine call, the program must return to the instruction immediately when the sub- routine has been carried out. this is done by placing a return instruction ret in the subroutine which will cause the program to jump back to the address right after the call instruction. in the case of a jmp instruction, the program simply jumps to the desired location. there is no requirement to jump back to the original jumping off point as in the case of the call instruction. one special and extremely useful set of branch instructions are the conditional branches. here a decision is first made re - garding the condition of a certain data memory or indi - vidual bits. depending upon the conditions, the program will continue with the next instruction or skip over it and jump to the following instruction. these instructions are the key to decision making and branching within the pro - gram perhaps determined by the condition of certain in - put switches or by the condition of internal data bits.
ht56r64 rev. 1.60 75 may 21, 2012 bit operations the ability to provide single bit operations on data mem - ory is an extremely flexible feature of all holtek microcontrollers. this feature is especially useful for output port bit programming where individual bits or port pins can be directly set high or low using either the set [m].i or  clr [m].i instructions respectively. the fea - ture removes the need for programmers to first read the 8-bit output port, manipulate the input data to ensure that other bits are not changed and then output the port with the correct new data. this read-modify-write pro - cess is taken care of automatically when these bit oper - ation instructions are used. table read operations data storage is normally implemented by using regis - ters. however, when working with large amounts of fixed data, the volume involved often makes it inconve - nient to store the fixed data in the data memory. to over - come this problem, holtek microcontrollers allow an area of program memory to be setup as a table where data can be directly stored. a set of easy to use instruc - tions provides the means by which this fixed data can be referenced and retrieved from the program memory. other operations in addition to the above functional instructions, a range of other instructions also exist such as the  halt in - struction for power-down operations and instructions to control the operation of the watchdog timer for reliable program operations under extreme electric or electro - magnetic environments. for their relevant operations, refer to the functional related sections. instruction set summary the following table depicts a summary of the instruction set categorised according to function and can be con - sulted as a basic instruction reference using the follow - ing listed conventions. table conventions: x: bits immediate data m: data memory address a: accumulator i: 0~7 number of bits addr: program memory address mnemonic description cycles flag affected arithmetic add a,[m] addm a,[m] add a,x adc a,[m] adcm a,[m] sub a,x sub a,[m] subm a,[m] sbc a,[m] sbcm a,[m] daa [m] add data memory to acc add acc to data memory add immediate data to acc add data memory to acc with carry add acc to data memory with carry subtract immediate data from the acc subtract data memory from acc subtract data memory from acc with result in data memory subtract data memory from acc with carry subtract data memory from acc with carry, result in data memory decimal adjust acc for addition with result in data memory 1 1 note 1 1 1 note 1 1 1 note 1 1 note 1 note z, c, ac, ov z, c, ac, ov z, c, ac, ov z, c, ac, ov z, c, ac, ov z, c, ac, ov z, c, ac, ov z, c, ac, ov z, c, ac, ov z, c, ac, ov c logic operation and a,[m] or a,[m] xor a,[m] andm a,[m] orm a,[m] xorm a,[m] and a,x or a,x xor a,x cpl [m] cpla [m] logical and data memory to acc logical or data memory to acc logical xor data memory to acc logical and acc to data memory logical or acc to data memory logical xor acc to data memory logical and immediate data to acc logical or immediate data to acc logical xor immediate data to acc complement data memory complement data memory with result in acc 1 1 1 1 note 1 note 1 note 1 1 1 1 note 1 z z z z z z z z z z z increment & decrement inca [m] inc [m] deca [m] dec [m] increment data memory with result in acc increment data memory decrement data memory with result in acc decrement data memory 1 1 note 1 1 note z z z z
ht56r64 rev. 1.60 76 may 21, 2012 mnemonic description cycles flag affected rotate rra [m] rr [m] rrca [m] rrc [m] rla [m] rl [m] rlca [m] rlc [m] rotate data memory right with result in acc rotate data memory right rotate data memory right through carry with result in acc rotate data memory right through carry rotate data memory left with result in acc rotate data memory left rotate data memory left through carry with result in acc rotate data memory left through carry 1 1 note 1 1 note 1 1 note 1 1 note none none c c none none c c data move mov a,[m] mov [m],a mov a,x move data memory to acc move acc to data memory move immediate data to acc 1 1 note 1 none none none bit operation clr [m].i set [m].i clear bit of data memory set bit of data memory 1 note 1 note none none branch jmp addr sz [m] sza [m] sz [m].i snz [m].i siz [m] sdz [m] siza [m] sdza [m] call addr ret ret a,x reti jump unconditionally skip if data memory is zero skip if data memory is zero with data movement to acc skip if bit i of data memory is zero skip if bit i of data memory is not zero skip if increment data memory is zero skip if decrement data memory is zero skip if increment data memory is zero with result in acc skip if decrement data memory is zero with result in acc subroutine call return from subroutine return from subroutine and load immediate data to acc return from interrupt 2 1 note 1 note 1 note 1 note 1 note 1 note 1 note 1 note 2 2 2 2 none none none none none none none none none none none none none table read tabrdc [m] tabrdl [m] read table (current page) to tblh and data memory read table (last page) to tblh and data memory 2 note 2 note none none miscellaneous nop clr [m] set [m] clr wdt clr wdt1 clr wdt2 swap [m] swapa [m] halt no operation clear data memory set data memory clear watchdog timer pre-clear watchdog timer pre-clear watchdog timer swap nibbles of data memory swap nibbles of data memory with result in acc enter power down mode 1 1 note 1 note 1 1 1 1 note 1 1 none none none to, pdf to, pdf to, pdf none none to, pdf note: 1. for skip instructions, if the result of the comparison involves a skip then two cycles are required, if no skip takes place only one cycle is required. 2. any instruction which changes the contents of the pcl will also require 2 cycles for execution. 3. for the  clr wdt1 and  clr wdt2 instructions the to and pdf flags may be affected by the execution status. the to and pdf flags are cleared after both  clr wdt1 and  clr wdt2 instructions are consecutively executed. otherwise the to and pdf flags remain unchanged.
instruction definition adc a,[m] add data memory to acc with carry description the contents of the specified data memory, accumulator and the carry flag are added. the result is stored in the accumulator. operation acc  acc+[m]+c affected flag(s) ov, z, ac, c adcm a,[m] add acc to data memory with carry description the contents of the specified data memory, accumulator and the carry flag are added. the result is stored in the specified data memory. operation [m]  acc+[m]+c affected flag(s) ov, z, ac, c add a,[m] add data memory to acc description the contents of the specified data memory and the accumulator are added. the result is stored in the accumulator. operation acc  acc + [m] affected flag(s) ov, z, ac, c add a,x add immediate data to acc description the contents of the accumulator and the specified immediate data are added. the result is stored in the accumulator. operation acc  acc+x affected flag(s) ov, z, ac, c addm a,[m] add acc to data memory description the contents of the specified data memory and the accumulator are added. the result is stored in the specified data memory. operation [m]  acc + [m] affected flag(s) ov, z, ac, c and a,[m] logical and data memory to acc description data in the accumulator and the specified data memory perform a bitwise logical and op - eration. the result is stored in the accumulator. operation acc  acc and [m] affected flag(s) z and a,x logical and immediate data to acc description data in the accumulator and the specified immediate data perform a bitwise logical and operation. the result is stored in the accumulator. operation acc  acc and x affected flag(s) z andm a,[m] logical and acc to data memory description data in the specified data memory and the accumulator perform a bitwise logical and op - eration. the result is stored in the data memory. operation [m]  acc and [m] affected flag(s) z ht56r64 rev. 1.60 77 may 21, 2012
call addr subroutine call description unconditionally calls a subroutine at the specified address. the program counter then in - crements by 1 to obtain the address of the next instruction which is then pushed onto the stack. the specified address is then loaded and the program continues execution from this new address. as this instruction requires an additional operation, it is a two cycle instruc - tion. operation stack  program counter + 1 program counter  addr affected flag(s) none clr [m] clear data memory description each bit of the specified data memory is cleared to 0. operation [m]  00h affected flag(s) none clr [m].i clear bit of data memory description bit i of the specified data memory is cleared to 0. operation [m].i  0 affected flag(s) none clr wdt clear watchdog timer description the to, pdf flags and the wdt are all cleared. operation wdt cleared to  0 pdf  0 affected flag(s) to, pdf clr wdt1 pre-clear watchdog timer description the to, pdf flags and the wdt are all cleared. note that this instruction works in conjunc- tion with clr wdt2 and must be executed alternately with clr wdt2 to have effect. re- petitively executing this instruction without alternately executing clr wdt2 will have no effect. operation wdt cleared to  0 pdf  0 affected flag(s) to, pdf clr wdt2 pre-clear watchdog timer description the to, pdf flags and the wdt are all cleared. note that this instruction works in conjunc - tion with clr wdt1 and must be executed alternately with clr wdt1 to have effect. re - petitively executing this instruction without alternately executing clr wdt1 will have no effect. operation wdt cleared to  0 pdf  0 affected flag(s) to, pdf ht56r64 rev. 1.60 78 may 21, 2012
cpl [m] complement data memory description each bit of the specified data memory is logically complemented (1
s complement). bits which previously contained a 1 are changed to 0 and vice versa. operation [m]  [m] affected flag(s) z cpla [m] complement data memory with result in acc description each bit of the specified data memory is logically complemented (1
s complement). bits which previously contained a 1 are changed to 0 and vice versa. the complemented result is stored in the accumulator and the contents of the data memory remain unchanged. operation acc  [m] affected flag(s) z daa [m] decimal-adjust acc for addition with result in data memory description convert the contents of the accumulator value to a bcd ( binary coded decimal) value re - sulting from the previous addition of two bcd variables. if the low nibble is greater than 9 or if ac flag is set, then a value of 6 will be added to the low nibble. otherwise the low nibble remains unchanged. if the high nibble is greater than 9 or if the c flag is set, then a value of 6 will be added to the high nibble. essentially, the decimal conversion is performed by add - ing 00h, 06h, 60h or 66h depending on the accumulator and flag conditions. only the c flag may be affected by this instruction which indicates that if the original bcd sum is greater than 100, it allows multiple precision decimal addition. operation [m]  acc + 00h or [m]  acc + 06h or [m]  acc + 60h or [m]  acc + 66h affected flag(s) c dec [m] decrement data memory description data in the specified data memory is decremented by 1. operation [m]  [m]  1 affected flag(s) z deca [m] decrement data memory with result in acc description data in the specified data memory is decremented by 1. the result is stored in the accu - mulator. the contents of the data memory remain unchanged. operation acc  [m]  1 affected flag(s) z halt enter power down mode description this instruction stops the program execution and turns off the system clock. the contents of the data memory and registers are retained. the wdt and prescaler are cleared. the power down flag pdf is set and the wdt time-out flag to is cleared. operation to  0 pdf  1 affected flag(s) to, pdf ht56r64 rev. 1.60 79 may 21, 2012
inc [m] increment data memory description data in the specified data memory is incremented by 1. operation [m]  [m]+1 affected flag(s) z inca [m] increment data memory with result in acc description data in the specified data memory is incremented by 1. the result is stored in the accumu - lator. the contents of the data memory remain unchanged. operation acc  [m]+1 affected flag(s) z jmp addr jump unconditionally description the contents of the program counter are replaced with the specified address. program execution then continues from this new address. as this requires the insertion of a dummy instruction while the new address is loaded, it is a two cycle instruction. operation program counter  addr affected flag(s) none mov a,[m] move data memory to acc description the contents of the specified data memory are copied to the accumulator. operation acc  [m] affected flag(s) none mov a,x move immediate data to acc description the immediate data specified is loaded into the accumulator. operation acc  x affected flag(s) none mov [m],a move acc to data memory description the contents of the accumulator are copied to the specified data memory. operation [m]  acc affected flag(s) none nop no operation description no operation is performed. execution continues with the next instruction. operation no operation affected flag(s) none or a,[m] logical or data memory to acc description data in the accumulator and the specified data memory perform a bitwise logical or oper - ation. the result is stored in the accumulator. operation acc  acc or [m] affected flag(s) z ht56r64 rev. 1.60 80 may 21, 2012
or a,x logical or immediate data to acc description data in the accumulator and the specified immediate data perform a bitwise logical or op - eration. the result is stored in the accumulator. operation acc  acc or x affected flag(s) z orm a,[m] logical or acc to data memory description data in the specified data memory and the accumulator perform a bitwise logical or oper - ation. the result is stored in the data memory. operation [m]  acc or [m] affected flag(s) z ret return from subroutine description the program counter is restored from the stack. program execution continues at the re - stored address. operation program counter  stack affected flag(s) none ret a,x return from subroutine and load immediate data to acc description the program counter is restored from the stack and the accumulator loaded with the specified immediate data. program execution continues at the restored address. operation program counter  stack acc  x affected flag(s) none reti return from interrupt description the program counter is restored from the stack and the interrupts are re-enabled by set- ting the emi bit. emi is the master interrupt global enable bit. if an interrupt was pending when the reti instruction is executed, the pending interrupt routine will be processed be- fore returning to the main program. operation program counter  stack emi  1 affected flag(s) none rl [m] rotate data memory left description the contents of the specified data memory are rotated left by 1 bit with bit 7 rotated into bit 0. operation [m].(i+1)  [m].i; (i = 0~6) [m].0  [m].7 affected flag(s) none rla [m] rotate data memory left with result in acc description the contents of the specified data memory are rotated left by 1 bit with bit 7 rotated into bit 0. the rotated result is stored in the accumulator and the contents of the data memory re - main unchanged. operation acc.(i+1)  [m].i; (i = 0~6) acc.0  [m].7 affected flag(s) none ht56r64 rev. 1.60 81 may 21, 2012
rlc [m] rotate data memory left through carry description the contents of the specified data memory and the carry flag are rotated left by 1 bit. bit 7 replaces the carry bit and the original carry flag is rotated into bit 0. operation [m].(i+1)  [m].i; (i = 0~6) [m].0  c c  [m].7 affected flag(s) c rlca [m] rotate data memory left through carry with result in acc description data in the specified data memory and the carry flag are rotated left by 1 bit. bit 7 replaces the carry bit and the original carry flag is rotated into the bit 0. the rotated result is stored in the accumulator and the contents of the data memory remain unchanged. operation acc.(i+1)  [m].i; (i = 0~6) acc.0  c c  [m].7 affected flag(s) c rr [m] rotate data memory right description the contents of the specified data memory are rotated right by 1 bit with bit 0 rotated into bit 7. operation [m].i  [m].(i+1); (i = 0~6) [m].7  [m].0 affected flag(s) none rra [m] rotate data memory right with result in acc description data in the specified data memory and the carry flag are rotated right by 1 bit with bit 0 ro- tated into bit 7. the rotated result is stored in the accumulator and the contents of the data memory remain unchanged. operation acc.i  [m].(i+1); (i = 0~6) acc.7  [m].0 affected flag(s) none rrc [m] rotate data memory right through carry description the contents of the specified data memory and the carry flag are rotated right by 1 bit. bit 0 replaces the carry bit and the original carry flag is rotated into bit 7. operation [m].i  [m].(i+1); (i = 0~6) [m].7  c c  [m].0 affected flag(s) c rrca [m] rotate data memory right through carry with result in acc description data in the specified data memory and the carry flag are rotated right by 1 bit. bit 0 re - places the carry bit and the original carry flag is rotated into bit 7. the rotated result is stored in the accumulator and the contents of the data memory remain unchanged. operation acc.i  [m].(i+1); (i = 0~6) acc.7  c c  [m].0 affected flag(s) c ht56r64 rev. 1.60 82 may 21, 2012
sbc a,[m] subtract data memory from acc with carry description the contents of the specified data memory and the complement of the carry flag are sub - tracted from the accumulator. the result is stored in the accumulator. note that if the result of subtraction is negative, the c flag will be cleared to 0, otherwise if the result is positive or zero, the c flag will be set to 1. operation acc  acc  [m]  c affected flag(s) ov, z, ac, c sbcm a,[m] subtract data memory from acc with carry and result in data memory description the contents of the specified data memory and the complement of the carry flag are sub - tracted from the accumulator. the result is stored in the data memory. note that if the re - sult of subtraction is negative, the c flag will be cleared to 0, otherwise if the result is positive or zero, the c flag will be set to 1. operation [m]  acc  [m]  c affected flag(s) ov, z, ac, c sdz [m] skip if decrement data memory is 0 description the contents of the specified data memory are first decremented by 1. if the result is 0 the following instruction is skipped. as this requires the insertion of a dummy instruction while the next instruction is fetched, it is a two cycle instruction. if the result is not 0 the program proceeds with the following instruction. operation [m]  [m]  1 skip if [m] = 0 affected flag(s) none sdza [m] skip if decrement data memory is zero with result in acc description the contents of the specified data memory are first decremented by 1. if the result is 0, the following instruction is skipped. the result is stored in the accumulator but the specified data memory contents remain unchanged. as this requires the insertion of a dummy in- struction while the next instruction is fetched, it is a two cycle instruction. if the result is not 0, the program proceeds with the following instruction. operation acc  [m]  1 skip if acc = 0 affected flag(s) none set [m] set data memory description each bit of the specified data memory is set to 1. operation [m]  ffh affected flag(s) none set [m].i set bit of data memory description bit i of the specified data memory is set to 1. operation [m].i  1 affected flag(s) none ht56r64 rev. 1.60 83 may 21, 2012
siz [m] skip if increment data memory is 0 description the contents of the specified data memory are first incremented by 1. if the result is 0, the following instruction is skipped. as this requires the insertion of a dummy instruction while the next instruction is fetched, it is a two cycle instruction. if the result is not 0 the program proceeds with the following instruction. operation [m]  [m]+1 skip if [m] = 0 affected flag(s) none siza [m] skip if increment data memory is zero with result in acc description the contents of the specified data memory are first incremented by 1. if the result is 0, the following instruction is skipped. the result is stored in the accumulator but the specified data memory contents remain unchanged. as this requires the insertion of a dummy in - struction while the next instruction is fetched, it is a two cycle instruction. if the result is not 0 the program proceeds with the following instruction. operation acc  [m]+1 skip if acc = 0 affected flag(s) none snz [m].i skip if bit i of data memory is not 0 description if bit i of the specified data memory is not 0, the following instruction is skipped. as this re - quires the insertion of a dummy instruction while the next instruction is fetched, it is a two cycle instruction. if the result is 0 the program proceeds with the following instruction. operation skip if [m].i  0 affected flag(s) none sub a,[m] subtract data memory from acc description the specified data memory is subtracted from the contents of the accumulator. the result is stored in the accumulator. note that if the result of subtraction is negative, the c flag will be cleared to 0, otherwise if the result is positive or zero, the c flag will be set to 1. operation acc  acc  [m] affected flag(s) ov, z, ac, c subm a,[m] subtract data memory from acc with result in data memory description the specified data memory is subtracted from the contents of the accumulator. the result is stored in the data memory. note that if the result of subtraction is negative, the c flag will be cleared to 0, otherwise if the result is positive or zero, the c flag will be set to 1. operation [m]  acc  [m] affected flag(s) ov, z, ac, c sub a,x subtract immediate data from acc description the immediate data specified by the code is subtracted from the contents of the accumu - lator. the result is stored in the accumulator. note that if the result of subtraction is nega - tive, the c flag will be cleared to 0, otherwise if the result is positive or zero, the c flag will be set to 1. operation acc  acc  x affected flag(s) ov, z, ac, c ht56r64 rev. 1.60 84 may 21, 2012
swap [m] swap nibbles of data memory description the low-order and high-order nibbles of the specified data memory are interchanged. operation [m].3~[m].0  [m].7 ~ [m].4 affected flag(s) none swapa [m] swap nibbles of data memory with result in acc description the low-order and high-order nibbles of the specified data memory are interchanged. the result is stored in the accumulator. the contents of the data memory remain unchanged. operation acc.3 ~ acc.0  [m].7 ~ [m].4 acc.7 ~ acc.4  [m].3 ~ [m].0 affected flag(s) none sz [m] skip if data memory is 0 description if the contents of the specified data memory is 0, the following instruction is skipped. as this requires the insertion of a dummy instruction while the next instruction is fetched, it is a two cycle instruction. if the result is not 0 the program proceeds with the following instruc - tion. operation skip if [m] = 0 affected flag(s) none sza [m] skip if data memory is 0 with data movement to acc description the contents of the specified data memory are copied to the accumulator. if the value is zero, the following instruction is skipped. as this requires the insertion of a dummy instruc - tion while the next instruction is fetched, it is a two cycle instruction. if the result is not 0 the program proceeds with the following instruction. operation acc  [m] skip if [m] = 0 affected flag(s) none sz [m].i skip if bit i of data memory is 0 description if bit i of the specified data memory is 0, the following instruction is skipped. as this re- quires the insertion of a dummy instruction while the next instruction is fetched, it is a two cycle instruction. if the result is not 0, the program proceeds with the following instruction. operation skip if [m].i = 0 affected flag(s) none tabrdc [m] read table (current page) to tblh and data memory description the low byte of the program code (current page) addressed by the table pointer (tblp) is moved to the specified data memory and the high byte moved to tblh. operation [m]  program code (low byte) tblh  program code (high byte) affected flag(s) none tabrdl [m] read table (last page) to tblh and data memory description the low byte of the program code (last page) addressed by the table pointer (tblp) is moved to the specified data memory and the high byte moved to tblh. operation [m]  program code (low byte) tblh  program code (high byte) affected flag(s) none ht56r64 rev. 1.60 85 may 21, 2012
xor a,[m] logical xor data memory to acc description data in the accumulator and the specified data memory perform a bitwise logical xor op - eration. the result is stored in the accumulator. operation acc  acc xor [m] affected flag(s) z xorm a,[m] logical xor acc to data memory description data in the specified data memory and the accumulator perform a bitwise logical xor op - eration. the result is stored in the data memory. operation [m]  acc xor [m] affected flag(s) z xor a,x logical xor immediate data to acc description data in the accumulator and the specified immediate data perform a bitwise logical xor operation. the result is stored in the accumulator. operation acc  acc xor x affected flag(s) z ht56r64 rev. 1.60 86 may 21, 2012
package information note that the package information provided here is for consultation purposes only. as this information may be updated at regu - lar intervals users are reminded to consult the holtek website ( http://www.holtek.com.tw/english/literature/package.pdf ) for the latest version of the package information. 52-pin qfp (14mm  14mm) outline dimensions symbol dimensions in inch min. nom. max. a 0.681  0.689 b 0.547  0.555 c 0.681  0.689 d 0.547  0.555 e  0.039  f  0.016  g 0.098  0.122 h  0.134 i  0.004  j 0.029  0.041 k 0.004  0.008  07 symbol dimensions in mm min. nom. max. a 17.30  17.50 b 13.90  14.10 c 17.30  17.50 d 13.90  14.10 e  1.00  f  0.40  g 2.50  3.10 h  3.40 i  0.10  j 0.73  1.03 k 0.10  0.20  07 ht56r64 rev. 1.60 87 may 21, 2012 0 5 1 6 2 . / . 4 / 0 ' 7 ( / 1 . 3 ! + - d  t ;
64-pin lqfp (7mm  7mm) outline dimensions symbol dimensions in inch min. nom. max. a 0.350  0.358 b 0.272  0.280 c 0.350  0.358 d 0.272  0.280 e  0.016  f 0.005  0.009 g 0.053  0.057 h  0.063 i 0.002  0.006 j 0.018  0.030 k 0.004  0.008  07 symbol dimensions in mm min. nom. max. a 8.90  9.10 b 6.90  7.10 c 8.90  9.10 d 6.90  7.10 e  0.40  f 0.13  0.23 g 1.35  1.45 h  1.60 i 0.05  0.15 j 0.45  0.75 k 0.09  0.20  07 ht56r64 rev. 1.60 88 may 21, 2012 1  1 5 0 0 0 . 3 1 / / 3 / 4 ' 7 ( ! + - d  t ;

100-pin lqfp (14mm  14mm) outline dimensions symbol dimensions in inch min. nom. max. a 0.626  0.634 b 0.547  0.555 c 0.626  0.634 d 0.547  0.555 e  0.020  f  0.008  g 0.053  0.057 h  0.063 i  0.004  j 0.018  0.030 k 0.004  0.008  07 symbol dimensions in mm min. nom. max. a 15.90  16.10 b 13.90  14.10 c 15.90  16.10 d 13.90  14.10 e  0.50  f  0.20  g 1.35  1.45 h  1.60 i  0.10  j 0.45  0.75 k 0.10  0.20  07 ht56r64 rev. 1.60 89 may 21, 2012 / 6 6 / . 2 ' 7 ( 2 6 . 3 ! + - d  t ;
2 / 4 2 4 3
ht56r64 rev. 1.60 90 may 21, 2012 copyright  2012 by holtek semiconductor inc. the information appearing in this data sheet is believed to be accurate at the time of publication. however, holtek as - sumes no responsibility arising from the use of the specifications described. the applications mentioned herein are used solely for the purpose of illustration and holtek makes no warranty or representation that such applications will be suitable without further modification, nor recommends the use of its products for application that may present a risk to human life due to malfunction or otherwise. holtek
s products are not authorized for use as critical components in life support devices or systems. holtek reserves the right to alter its products without prior notification. for the most up-to-date information, please visit our web site at http://www.holtek.com.tw. holtek semiconductor inc. (headquarters) no.3, creation rd. ii, science park, hsinchu, taiwan tel: 886-3-563-1999 fax: 886-3-563-1189 http://www.holtek.com.tw holtek semiconductor inc. (taipei sales office) 4f-2, no. 3-2, yuanqu st., nankang software park, taipei 115, taiwan tel: 886-2-2655-7070 fax: 886-2-2655-7373 fax: 886-2-2655-7383 (international sales hotline) holtek semiconductor inc. (shenzhen sales office) 5f, unit a, productivity building, no.5 gaoxin m 2nd road, nanshan district, shenzhen, china 518057 tel: 86-755-8616-9908, 86-755-8616-9308 fax: 86-755-8616-9722 holtek semiconductor (usa), inc. (north america sales office) 46729 fremont blvd., fremont, ca 94538, usa tel: 1-510-252-9880 fax: 1-510-252-9885 http://www.holtek.com


▲Up To Search▲   

 
Price & Availability of HT56R6412

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X